Remove body_as_json
in favor of built-in response.parsed_body
for JSON response specs (#31749)
This commit is contained in:
parent
be77a1098b
commit
6b6a80b407
107 changed files with 422 additions and 413 deletions
|
@ -31,7 +31,7 @@ RSpec.describe ActivityPub::CollectionsController do
|
|||
.and have_cacheable_headers
|
||||
expect(response.media_type).to eq 'application/activity+json'
|
||||
|
||||
expect(body_as_json[:orderedItems])
|
||||
expect(response.parsed_body[:orderedItems])
|
||||
.to be_an(Array)
|
||||
.and have_attributes(size: 3)
|
||||
.and include(ActivityPub::TagManager.instance.uri_for(private_pinned))
|
||||
|
@ -71,7 +71,7 @@ RSpec.describe ActivityPub::CollectionsController do
|
|||
|
||||
expect(response.media_type).to eq 'application/activity+json'
|
||||
|
||||
expect(body_as_json[:orderedItems])
|
||||
expect(response.parsed_body[:orderedItems])
|
||||
.to be_an(Array)
|
||||
.and have_attributes(size: 3)
|
||||
.and include(ActivityPub::TagManager.instance.uri_for(private_pinned))
|
||||
|
@ -94,7 +94,7 @@ RSpec.describe ActivityPub::CollectionsController do
|
|||
expect(response.media_type).to eq 'application/activity+json'
|
||||
expect(response.headers['Cache-Control']).to include 'private'
|
||||
|
||||
expect(body_as_json[:orderedItems])
|
||||
expect(response.parsed_body[:orderedItems])
|
||||
.to be_an(Array)
|
||||
.and be_empty
|
||||
end
|
||||
|
@ -110,7 +110,7 @@ RSpec.describe ActivityPub::CollectionsController do
|
|||
expect(response.media_type).to eq 'application/activity+json'
|
||||
expect(response.headers['Cache-Control']).to include 'private'
|
||||
|
||||
expect(body_as_json[:orderedItems])
|
||||
expect(response.parsed_body[:orderedItems])
|
||||
.to be_an(Array)
|
||||
.and be_empty
|
||||
end
|
||||
|
|
|
@ -34,7 +34,6 @@ RSpec.describe ActivityPub::FollowersSynchronizationsController do
|
|||
context 'with signature from example.com' do
|
||||
subject(:response) { get :show, params: { account_username: account.username } }
|
||||
|
||||
let(:body) { body_as_json }
|
||||
let(:remote_account) { Fabricate(:account, domain: 'example.com', uri: 'https://example.com/instance') }
|
||||
|
||||
it 'returns http success and cache control and activity json types and correct items' do
|
||||
|
@ -42,7 +41,7 @@ RSpec.describe ActivityPub::FollowersSynchronizationsController do
|
|||
expect(response.headers['Cache-Control']).to eq 'max-age=0, private'
|
||||
expect(response.media_type).to eq 'application/activity+json'
|
||||
|
||||
expect(body[:orderedItems])
|
||||
expect(response.parsed_body[:orderedItems])
|
||||
.to be_an(Array)
|
||||
.and contain_exactly(
|
||||
follower_example_com_instance_actor.uri,
|
||||
|
|
|
@ -19,7 +19,6 @@ RSpec.describe ActivityPub::OutboxesController do
|
|||
context 'without signature' do
|
||||
subject(:response) { get :show, params: { account_username: account.username, page: page } }
|
||||
|
||||
let(:body) { body_as_json }
|
||||
let(:remote_account) { nil }
|
||||
|
||||
context 'with page not requested' do
|
||||
|
@ -32,7 +31,7 @@ RSpec.describe ActivityPub::OutboxesController do
|
|||
|
||||
expect(response.media_type).to eq 'application/activity+json'
|
||||
expect(response.headers['Vary']).to be_nil
|
||||
expect(body[:totalItems]).to eq 4
|
||||
expect(response.parsed_body[:totalItems]).to eq 4
|
||||
end
|
||||
|
||||
context 'when account is permanently suspended' do
|
||||
|
@ -68,9 +67,11 @@ RSpec.describe ActivityPub::OutboxesController do
|
|||
expect(response.media_type).to eq 'application/activity+json'
|
||||
expect(response.headers['Vary']).to include 'Signature'
|
||||
|
||||
expect(body[:orderedItems]).to be_an Array
|
||||
expect(body[:orderedItems].size).to eq 2
|
||||
expect(body[:orderedItems].all? { |item| targets_public_collection?(item) }).to be true
|
||||
expect(response.parsed_body)
|
||||
.to include(
|
||||
orderedItems: be_an(Array).and(have_attributes(size: 2))
|
||||
)
|
||||
expect(response.parsed_body[:orderedItems].all? { |item| targets_public_collection?(item) }).to be true
|
||||
end
|
||||
|
||||
context 'when account is permanently suspended' do
|
||||
|
@ -110,9 +111,11 @@ RSpec.describe ActivityPub::OutboxesController do
|
|||
expect(response.media_type).to eq 'application/activity+json'
|
||||
expect(response.headers['Cache-Control']).to eq 'max-age=60, private'
|
||||
|
||||
expect(body_as_json[:orderedItems]).to be_an Array
|
||||
expect(body_as_json[:orderedItems].size).to eq 2
|
||||
expect(body_as_json[:orderedItems].all? { |item| targets_public_collection?(item) }).to be true
|
||||
expect(response.parsed_body)
|
||||
.to include(
|
||||
orderedItems: be_an(Array).and(have_attributes(size: 2))
|
||||
)
|
||||
expect(response.parsed_body[:orderedItems].all? { |item| targets_public_collection?(item) }).to be true
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -127,9 +130,11 @@ RSpec.describe ActivityPub::OutboxesController do
|
|||
expect(response.media_type).to eq 'application/activity+json'
|
||||
expect(response.headers['Cache-Control']).to eq 'max-age=60, private'
|
||||
|
||||
expect(body_as_json[:orderedItems]).to be_an Array
|
||||
expect(body_as_json[:orderedItems].size).to eq 3
|
||||
expect(body_as_json[:orderedItems].all? { |item| targets_public_collection?(item) || targets_followers_collection?(item, account) }).to be true
|
||||
expect(response.parsed_body)
|
||||
.to include(
|
||||
orderedItems: be_an(Array).and(have_attributes(size: 3))
|
||||
)
|
||||
expect(response.parsed_body[:orderedItems].all? { |item| targets_public_collection?(item) || targets_followers_collection?(item, account) }).to be true
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -144,9 +149,10 @@ RSpec.describe ActivityPub::OutboxesController do
|
|||
expect(response.media_type).to eq 'application/activity+json'
|
||||
expect(response.headers['Cache-Control']).to eq 'max-age=60, private'
|
||||
|
||||
expect(body_as_json[:orderedItems])
|
||||
.to be_an(Array)
|
||||
.and be_empty
|
||||
expect(response.parsed_body)
|
||||
.to include(
|
||||
orderedItems: be_an(Array).and(be_empty)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -161,9 +167,10 @@ RSpec.describe ActivityPub::OutboxesController do
|
|||
expect(response.media_type).to eq 'application/activity+json'
|
||||
expect(response.headers['Cache-Control']).to eq 'max-age=60, private'
|
||||
|
||||
expect(body_as_json[:orderedItems])
|
||||
.to be_an(Array)
|
||||
.and be_empty
|
||||
expect(response.parsed_body)
|
||||
.to include(
|
||||
orderedItems: be_an(Array).and(be_empty)
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -66,7 +66,7 @@ RSpec.describe ActivityPub::RepliesController do
|
|||
|
||||
context 'when status is public' do
|
||||
let(:parent_visibility) { :public }
|
||||
let(:page_json) { body_as_json[:first] }
|
||||
let(:page_json) { response.parsed_body[:first] }
|
||||
|
||||
it 'returns http success and correct media type' do
|
||||
expect(response)
|
||||
|
|
|
@ -402,7 +402,7 @@ RSpec.describe Auth::SessionsController do
|
|||
end
|
||||
|
||||
it 'instructs the browser to redirect to home, logs the user in, and updates the sign count' do
|
||||
expect(body_as_json[:redirect_path]).to eq(root_path)
|
||||
expect(response.parsed_body[:redirect_path]).to eq(root_path)
|
||||
|
||||
expect(controller.current_user).to eq user
|
||||
|
||||
|
|
|
@ -39,8 +39,6 @@ RSpec.describe FollowerAccountsController do
|
|||
end
|
||||
|
||||
context 'when format is json' do
|
||||
subject(:body) { response.parsed_body }
|
||||
|
||||
let(:response) { get :index, params: { account_username: alice.username, page: page, format: :json } }
|
||||
|
||||
context 'with page' do
|
||||
|
@ -48,15 +46,15 @@ RSpec.describe FollowerAccountsController do
|
|||
|
||||
it 'returns followers' do
|
||||
expect(response).to have_http_status(200)
|
||||
expect(body_as_json)
|
||||
expect(response.parsed_body)
|
||||
.to include(
|
||||
orderedItems: contain_exactly(
|
||||
include(follow_from_bob.account.username),
|
||||
include(follow_from_chris.account.username)
|
||||
)
|
||||
),
|
||||
totalItems: eq(2),
|
||||
partOf: be_present
|
||||
)
|
||||
expect(body['totalItems']).to eq 2
|
||||
expect(body['partOf']).to be_present
|
||||
end
|
||||
|
||||
context 'when account is permanently suspended' do
|
||||
|
@ -86,8 +84,11 @@ RSpec.describe FollowerAccountsController do
|
|||
|
||||
it 'returns followers' do
|
||||
expect(response).to have_http_status(200)
|
||||
expect(body['totalItems']).to eq 2
|
||||
expect(body['partOf']).to be_blank
|
||||
expect(response.parsed_body)
|
||||
.to include(
|
||||
totalItems: eq(2)
|
||||
)
|
||||
.and not_include(:partOf)
|
||||
end
|
||||
|
||||
context 'when account hides their network' do
|
||||
|
@ -95,15 +96,17 @@ RSpec.describe FollowerAccountsController do
|
|||
alice.update(hide_collections: true)
|
||||
end
|
||||
|
||||
it 'returns followers count' do
|
||||
expect(body['totalItems']).to eq 2
|
||||
end
|
||||
|
||||
it 'does not return items' do
|
||||
expect(body['items']).to be_blank
|
||||
expect(body['orderedItems']).to be_blank
|
||||
expect(body['first']).to be_blank
|
||||
expect(body['last']).to be_blank
|
||||
it 'returns followers count but not any items' do
|
||||
expect(response.parsed_body)
|
||||
.to include(
|
||||
totalItems: eq(2)
|
||||
)
|
||||
.and not_include(
|
||||
:items,
|
||||
:orderedItems,
|
||||
:first,
|
||||
:last
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -39,8 +39,6 @@ RSpec.describe FollowingAccountsController do
|
|||
end
|
||||
|
||||
context 'when format is json' do
|
||||
subject(:body) { response.parsed_body }
|
||||
|
||||
let(:response) { get :index, params: { account_username: alice.username, page: page, format: :json } }
|
||||
|
||||
context 'with page' do
|
||||
|
@ -48,15 +46,15 @@ RSpec.describe FollowingAccountsController do
|
|||
|
||||
it 'returns followers' do
|
||||
expect(response).to have_http_status(200)
|
||||
expect(body_as_json)
|
||||
expect(response.parsed_body)
|
||||
.to include(
|
||||
orderedItems: contain_exactly(
|
||||
include(follow_of_bob.target_account.username),
|
||||
include(follow_of_chris.target_account.username)
|
||||
)
|
||||
),
|
||||
totalItems: eq(2),
|
||||
partOf: be_present
|
||||
)
|
||||
expect(body['totalItems']).to eq 2
|
||||
expect(body['partOf']).to be_present
|
||||
end
|
||||
|
||||
context 'when account is permanently suspended' do
|
||||
|
@ -86,8 +84,11 @@ RSpec.describe FollowingAccountsController do
|
|||
|
||||
it 'returns followers' do
|
||||
expect(response).to have_http_status(200)
|
||||
expect(body['totalItems']).to eq 2
|
||||
expect(body['partOf']).to be_blank
|
||||
expect(response.parsed_body)
|
||||
.to include(
|
||||
totalItems: eq(2)
|
||||
)
|
||||
.and not_include(:partOf)
|
||||
end
|
||||
|
||||
context 'when account hides their network' do
|
||||
|
@ -95,15 +96,17 @@ RSpec.describe FollowingAccountsController do
|
|||
alice.update(hide_collections: true)
|
||||
end
|
||||
|
||||
it 'returns followers count' do
|
||||
expect(body['totalItems']).to eq 2
|
||||
end
|
||||
|
||||
it 'does not return items' do
|
||||
expect(body['items']).to be_blank
|
||||
expect(body['orderedItems']).to be_blank
|
||||
expect(body['first']).to be_blank
|
||||
expect(body['last']).to be_blank
|
||||
it 'returns followers count but not any items' do
|
||||
expect(response.parsed_body)
|
||||
.to include(
|
||||
totalItems: eq(2)
|
||||
)
|
||||
.and not_include(
|
||||
:items,
|
||||
:orderedItems,
|
||||
:first,
|
||||
:last
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -81,7 +81,7 @@ RSpec.describe StatusesController do
|
|||
'Content-Type' => include('application/activity+json'),
|
||||
'Link' => satisfy { |header| header.to_s.include?('activity+json') }
|
||||
)
|
||||
expect(body_as_json)
|
||||
expect(response.parsed_body)
|
||||
.to include(content: include(status.text))
|
||||
end
|
||||
end
|
||||
|
@ -186,7 +186,7 @@ RSpec.describe StatusesController do
|
|||
'Content-Type' => include('application/activity+json'),
|
||||
'Link' => satisfy { |header| header.to_s.include?('activity+json') }
|
||||
)
|
||||
expect(body_as_json)
|
||||
expect(response.parsed_body)
|
||||
.to include(content: include(status.text))
|
||||
end
|
||||
end
|
||||
|
@ -230,7 +230,7 @@ RSpec.describe StatusesController do
|
|||
'Content-Type' => include('application/activity+json'),
|
||||
'Link' => satisfy { |header| header.to_s.include?('activity+json') }
|
||||
)
|
||||
expect(body_as_json)
|
||||
expect(response.parsed_body)
|
||||
.to include(content: include(status.text))
|
||||
end
|
||||
end
|
||||
|
@ -296,7 +296,7 @@ RSpec.describe StatusesController do
|
|||
'Content-Type' => include('application/activity+json'),
|
||||
'Link' => satisfy { |header| header.to_s.include?('activity+json') }
|
||||
)
|
||||
expect(body_as_json)
|
||||
expect(response.parsed_body)
|
||||
.to include(content: include(status.text))
|
||||
end
|
||||
end
|
||||
|
@ -387,7 +387,7 @@ RSpec.describe StatusesController do
|
|||
'Content-Type' => include('application/activity+json'),
|
||||
'Link' => satisfy { |header| header.to_s.include?('activity+json') }
|
||||
)
|
||||
expect(body_as_json)
|
||||
expect(response.parsed_body)
|
||||
.to include(content: include(status.text))
|
||||
end
|
||||
end
|
||||
|
@ -431,7 +431,7 @@ RSpec.describe StatusesController do
|
|||
'Link' => satisfy { |header| header.to_s.include?('activity+json') }
|
||||
)
|
||||
|
||||
expect(body_as_json)
|
||||
expect(response.parsed_body)
|
||||
.to include(content: include(status.text))
|
||||
end
|
||||
end
|
||||
|
@ -497,7 +497,7 @@ RSpec.describe StatusesController do
|
|||
'Content-Type' => include('application/activity+json'),
|
||||
'Link' => satisfy { |header| header.to_s.include?('activity+json') }
|
||||
)
|
||||
expect(body_as_json)
|
||||
expect(response.parsed_body)
|
||||
.to include(content: include(status.text))
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue