0
0
Fork 0

Remove body_as_json in favor of built-in response.parsed_body for JSON response specs (#31749)

This commit is contained in:
Matt Jankowski 2024-09-06 05:58:46 -04:00 committed by GitHub
parent be77a1098b
commit 6b6a80b407
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
107 changed files with 422 additions and 413 deletions

View file

@ -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