diff options
author | Evan Minto <evan.minto@gmail.com> | 2017-04-25 06:06:06 -0700 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2017-04-25 15:06:06 +0200 |
commit | 122d59ac41a0c637b19357c2b7422002ffa0381c (patch) | |
tree | 150a8793fcc7d51793a24b2b1df900025799dc73 /spec | |
parent | 8b5179d006a07cf759e751e9d883bfe472cee868 (diff) |
Change ActivityPub paging to match spec. Clean up ActivityPub outbox changes. (#2410)
* Change ActivityPub paging to match spec. Clean up ActivityPub outbox changes. * Fix code style and test failures for OutboxController. * Attempt to fix CI errors.
Diffstat (limited to 'spec')
3 files changed, 111 insertions, 63 deletions
diff --git a/spec/controllers/api/activitypub/activities_controller_spec.rb b/spec/controllers/api/activitypub/activities_controller_spec.rb index 2de530289..2c966a45a 100644 --- a/spec/controllers/api/activitypub/activities_controller_spec.rb +++ b/spec/controllers/api/activitypub/activities_controller_spec.rb @@ -10,7 +10,7 @@ RSpec.describe Api::Activitypub::ActivitiesController, type: :controller do public_status = nil before do - public_status = Status.create!(account: user.account, text: 'Hello world', visibility: :public) + public_status = Fabricate(:status, account: user.account, text: 'Hello world', visibility: :public) @request.env['HTTP_ACCEPT'] = 'application/activity+json' get :show_status, params: { id: public_status.id } @@ -24,10 +24,6 @@ RSpec.describe Api::Activitypub::ActivitiesController, type: :controller do expect(response.header['Content-Type']).to include 'application/activity+json' end - it 'sets Access-Control-Allow-Origin header to *' do - expect(response.header['Access-Control-Allow-Origin']).to eq '*' - end - it 'returns http success' do json_data = JSON.parse(response.body) expect(json_data).to include('@context' => 'https://www.w3.org/ns/activitystreams') @@ -44,8 +40,8 @@ RSpec.describe Api::Activitypub::ActivitiesController, type: :controller do reblog = nil before do - original = Status.create!(account: user.account, text: 'Hello world', visibility: :public) - reblog = Status.create!(account: user.account, reblog_of_id: original.id, visibility: :public) + original = Fabricate(:status, account: user.account, text: 'Hello world', visibility: :public) + reblog = Fabricate(:status, account: user.account, reblog_of_id: original.id, visibility: :public) @request.env['HTTP_ACCEPT'] = 'application/activity+json' get :show_status, params: { id: reblog.id } @@ -59,10 +55,6 @@ RSpec.describe Api::Activitypub::ActivitiesController, type: :controller do expect(response.header['Content-Type']).to include 'application/activity+json' end - it 'sets Access-Control-Allow-Origin header to *' do - expect(response.header['Access-Control-Allow-Origin']).to eq '*' - end - it 'returns http success' do json_data = JSON.parse(response.body) expect(json_data).to include('@context' => 'https://www.w3.org/ns/activitystreams') diff --git a/spec/controllers/api/activitypub/notes_controller_spec.rb b/spec/controllers/api/activitypub/notes_controller_spec.rb index 8b8db2fec..39ddec03e 100644 --- a/spec/controllers/api/activitypub/notes_controller_spec.rb +++ b/spec/controllers/api/activitypub/notes_controller_spec.rb @@ -11,7 +11,7 @@ RSpec.describe Api::Activitypub::NotesController, type: :controller do public_status = nil before do - public_status = Status.create!(account: user_alice.account, text: 'Hello world', visibility: :public) + public_status = Fabricate(:status, account: user_alice.account, text: 'Hello world', visibility: :public) @request.env['HTTP_ACCEPT'] = 'application/activity+json' get :show, params: { id: public_status.id } @@ -25,10 +25,6 @@ RSpec.describe Api::Activitypub::NotesController, type: :controller do expect(response.header['Content-Type']).to include 'application/activity+json' end - it 'sets Access-Control-Allow-Origin header to *' do - expect(response.header['Access-Control-Allow-Origin']).to eq '*' - end - it 'returns http success' do json_data = JSON.parse(response.body) expect(json_data).to include('@context' => 'https://www.w3.org/ns/activitystreams') @@ -46,8 +42,8 @@ RSpec.describe Api::Activitypub::NotesController, type: :controller do reply = nil before do - original = Status.create!(account: user_alice.account, text: 'Hello world', visibility: :public) - reply = Status.create!(account: user_bob.account, text: 'Hello world', in_reply_to_id: original.id, visibility: :public) + original = Fabricate(:status, account: user_alice.account, text: 'Hello world', visibility: :public) + reply = Fabricate(:status, account: user_bob.account, text: 'Hello world', in_reply_to_id: original.id, visibility: :public) @request.env['HTTP_ACCEPT'] = 'application/activity+json' get :show, params: { id: reply.id } @@ -61,10 +57,6 @@ RSpec.describe Api::Activitypub::NotesController, type: :controller do expect(response.header['Content-Type']).to include 'application/activity+json' end - it 'sets Access-Control-Allow-Origin header to *' do - expect(response.header['Access-Control-Allow-Origin']).to eq '*' - end - it 'returns http success' do json_data = JSON.parse(response.body) expect(json_data).to include('@context' => 'https://www.w3.org/ns/activitystreams') diff --git a/spec/controllers/api/activitypub/outbox_controller_spec.rb b/spec/controllers/api/activitypub/outbox_controller_spec.rb index 9a47dde6b..99797c582 100644 --- a/spec/controllers/api/activitypub/outbox_controller_spec.rb +++ b/spec/controllers/api/activitypub/outbox_controller_spec.rb @@ -7,17 +7,17 @@ RSpec.describe Api::Activitypub::OutboxController, type: :controller do describe 'GET #show' do before do - @request.env['HTTP_ACCEPT'] = 'application/activity+json' + @request.headers['ACCEPT'] = 'application/activity+json' end - describe 'small number of statuses' do + describe 'collection with small number of statuses' do public_status = nil before do - public_status = Status.create!(account: user.account, text: 'Hello world', visibility: :public) - Status.create!(account: user.account, text: 'Hello world', visibility: :private) - Status.create!(account: user.account, text: 'Hello world', visibility: :unlisted) - Status.create!(account: user.account, text: 'Hello world', visibility: :direct) + public_status = Fabricate(:status, account: user.account, text: 'Hello world', visibility: :public) + Fabricate(:status, account: user.account, text: 'Hello world', visibility: :private) + Fabricate(:status, account: user.account, text: 'Hello world', visibility: :unlisted) + Fabricate(:status, account: user.account, text: 'Hello world', visibility: :direct) get :show, params: { id: user.account.id } end @@ -30,62 +30,126 @@ RSpec.describe Api::Activitypub::OutboxController, type: :controller do expect(response.header['Content-Type']).to include 'application/activity+json' end - it 'sets Access-Control-Allow-Origin header to *' do - expect(response.header['Access-Control-Allow-Origin']).to eq '*' - end - it 'returns AS2 JSON body' do json_data = JSON.parse(response.body) expect(json_data).to include('@context' => 'https://www.w3.org/ns/activitystreams') expect(json_data).to include('id' => @request.url) expect(json_data).to include('type' => 'OrderedCollection') expect(json_data).to include('totalItems' => 1) - expect(json_data).to include('items') - expect(json_data['items'].count).to eq(1) - expect(json_data['items']).to include(api_activitypub_status_url(public_status)) + expect(json_data).to include('current') + expect(json_data).to include('first') + expect(json_data).to include('last') end end - describe 'large number of statuses' do + describe 'collection with large number of statuses' do before do 30.times do - Status.create!(account: user.account, text: 'Hello world', visibility: :public) + Fabricate(:status, account: user.account, text: 'Hello world', visibility: :public) end - Status.create!(account: user.account, text: 'Hello world', visibility: :private) - Status.create!(account: user.account, text: 'Hello world', visibility: :unlisted) - Status.create!(account: user.account, text: 'Hello world', visibility: :direct) + Fabricate(:status, account: user.account, text: 'Hello world', visibility: :private) + Fabricate(:status, account: user.account, text: 'Hello world', visibility: :unlisted) + Fabricate(:status, account: user.account, text: 'Hello world', visibility: :direct) + + get :show, params: { id: user.account.id } end - describe 'first page' do - before do - get :show, params: { id: user.account.id } - end + it 'returns http success' do + expect(response).to have_http_status(:success) + end - it 'returns http success' do - expect(response).to have_http_status(:success) - end + it 'sets Content-Type header to AS2' do + expect(response.header['Content-Type']).to include 'application/activity+json' + end - it 'sets Content-Type header to AS2' do - expect(response.header['Content-Type']).to include 'application/activity+json' - end + it 'returns AS2 JSON body' do + json_data = JSON.parse(response.body) + expect(json_data).to include('@context' => 'https://www.w3.org/ns/activitystreams') + expect(json_data).to include('id' => @request.url) + expect(json_data).to include('type' => 'OrderedCollection') + expect(json_data).to include('totalItems' => 30) + expect(json_data).to include('current') + expect(json_data).to include('first') + expect(json_data).to include('last') + end + end + + describe 'page with small number of statuses' do + statuses = [] - it 'sets Access-Control-Allow-Origin header to *' do - expect(response.header['Access-Control-Allow-Origin']).to eq '*' + before do + 5.times do + statuses << Fabricate(:status, account: user.account, text: 'Hello world', visibility: :public) end - it 'returns AS2 JSON body' do - json_data = JSON.parse(response.body) - expect(json_data).to include('@context' => 'https://www.w3.org/ns/activitystreams') - expect(json_data).to include('id' => @request.url) - expect(json_data).to include('type' => 'OrderedCollectionPage') - expect(json_data).to include('totalItems' => 20) - expect(json_data).to include('items') - expect(json_data['items'].count).to eq(20) - expect(json_data).to include('current' => @request.url) - expect(json_data).to include('next') - expect(json_data).to_not include('prev') + Fabricate(:status, account: user.account, text: 'Hello world', visibility: :private) + Fabricate(:status, account: user.account, text: 'Hello world', visibility: :unlisted) + Fabricate(:status, account: user.account, text: 'Hello world', visibility: :direct) + + get :show, params: { id: user.account.id, max_id: statuses.last.id + 1 } + end + + it 'returns http success' do + expect(response).to have_http_status(:success) + end + + it 'sets Content-Type header to AS2' do + expect(response.header['Content-Type']).to include 'application/activity+json' + end + + it 'returns AS2 JSON body' do + json_data = JSON.parse(response.body) + expect(json_data).to include('@context' => 'https://www.w3.org/ns/activitystreams') + expect(json_data).to include('id' => @request.url) + expect(json_data).to include('type' => 'OrderedCollectionPage') + expect(json_data).to include('partOf') + expect(json_data).to include('items') + expect(json_data['items'].length).to eq(5) + expect(json_data).to include('prev') + expect(json_data).to include('next') + expect(json_data).to include('current') + expect(json_data).to include('first') + expect(json_data).to include('last') + end + end + + describe 'page with large number of statuses' do + statuses = [] + + before do + 30.times do + statuses << Fabricate(:status, account: user.account, text: 'Hello world', visibility: :public) end + + Fabricate(:status, account: user.account, text: 'Hello world', visibility: :private) + Fabricate(:status, account: user.account, text: 'Hello world', visibility: :unlisted) + Fabricate(:status, account: user.account, text: 'Hello world', visibility: :direct) + + get :show, params: { id: user.account.id, max_id: statuses.last.id + 1 } + end + + it 'returns http success' do + expect(response).to have_http_status(:success) + end + + it 'sets Content-Type header to AS2' do + expect(response.header['Content-Type']).to include 'application/activity+json' + end + + it 'returns AS2 JSON body' do + json_data = JSON.parse(response.body) + expect(json_data).to include('@context' => 'https://www.w3.org/ns/activitystreams') + expect(json_data).to include('id' => @request.url) + expect(json_data).to include('type' => 'OrderedCollectionPage') + expect(json_data).to include('partOf') + expect(json_data).to include('items') + expect(json_data['items'].length).to eq(20) + expect(json_data).to include('prev') + expect(json_data).to include('next') + expect(json_data).to include('current') + expect(json_data).to include('first') + expect(json_data).to include('last') end end end |