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

@ -76,7 +76,7 @@ RSpec.describe 'API V2 Admin Accounts' do
end
def body_json_ids
body_as_json.map { |a| a[:id].to_i }
response.parsed_body.map { |a| a[:id].to_i }
end
context 'with limit param' do

View file

@ -17,7 +17,7 @@ RSpec.describe 'API V2 Filters Keywords' do
it 'returns http success' do
get "/api/v2/filters/#{filter.id}/keywords", headers: headers
expect(response).to have_http_status(200)
expect(body_as_json)
expect(response.parsed_body)
.to contain_exactly(
include(id: keyword.id.to_s)
)
@ -42,7 +42,7 @@ RSpec.describe 'API V2 Filters Keywords' do
it 'creates a filter', :aggregate_failures do
expect(response).to have_http_status(200)
expect(body_as_json)
expect(response.parsed_body)
.to include(
keyword: 'magic',
whole_word: false
@ -73,7 +73,7 @@ RSpec.describe 'API V2 Filters Keywords' do
it 'responds with the keyword', :aggregate_failures do
expect(response).to have_http_status(200)
expect(body_as_json)
expect(response.parsed_body)
.to include(
keyword: 'foo',
whole_word: false

View file

@ -17,7 +17,7 @@ RSpec.describe 'API V2 Filters Statuses' do
it 'returns http success' do
get "/api/v2/filters/#{filter.id}/statuses", headers: headers
expect(response).to have_http_status(200)
expect(body_as_json)
expect(response.parsed_body)
.to contain_exactly(
include(id: status_filter.id.to_s)
)
@ -43,7 +43,7 @@ RSpec.describe 'API V2 Filters Statuses' do
it 'creates a filter', :aggregate_failures do
expect(response).to have_http_status(200)
expect(body_as_json)
expect(response.parsed_body)
.to include(
status_id: status.id.to_s
)
@ -73,7 +73,7 @@ RSpec.describe 'API V2 Filters Statuses' do
it 'responds with the filter', :aggregate_failures do
expect(response).to have_http_status(200)
expect(body_as_json)
expect(response.parsed_body)
.to include(
status_id: status_filter.status.id.to_s
)

View file

@ -32,7 +32,7 @@ RSpec.describe 'Filters' do
subject
expect(response).to have_http_status(200)
expect(body_as_json.pluck(:id)).to match_array(filters.map { |filter| filter.id.to_s })
expect(response.parsed_body.pluck(:id)).to match_array(filters.map { |filter| filter.id.to_s })
end
end
@ -58,7 +58,7 @@ RSpec.describe 'Filters' do
it 'returns a filter with keywords', :aggregate_failures do
subject
expect(body_as_json)
expect(response.parsed_body)
.to include(
title: 'magic',
filter_action: 'hide',
@ -127,7 +127,10 @@ RSpec.describe 'Filters' do
subject
expect(response).to have_http_status(200)
expect(body_as_json[:id]).to eq(filter.id.to_s)
expect(response.parsed_body)
.to include(
id: filter.id.to_s
)
end
context 'when the filter belongs to someone else' do

View file

@ -15,7 +15,7 @@ RSpec.describe 'Instances' do
expect(response)
.to have_http_status(200)
expect(body_as_json)
expect(response.parsed_body)
.to be_present
.and include(title: 'Mastodon')
.and include_api_versions
@ -30,7 +30,7 @@ RSpec.describe 'Instances' do
expect(response)
.to have_http_status(200)
expect(body_as_json)
expect(response.parsed_body)
.to be_present
.and include(title: 'Mastodon')
.and include_api_versions

View file

@ -21,7 +21,7 @@ RSpec.describe 'Media API', :attachment_processing do
expect(response)
.to have_http_status(200)
expect(body_as_json)
expect(response.parsed_body)
.to be_a(Hash)
end
end
@ -38,7 +38,7 @@ RSpec.describe 'Media API', :attachment_processing do
expect(response)
.to have_http_status(202)
expect(body_as_json)
expect(response.parsed_body)
.to be_a(Hash)
end
end
@ -63,7 +63,7 @@ RSpec.describe 'Media API', :attachment_processing do
expect(response)
.to have_http_status(422)
expect(body_as_json)
expect(response.parsed_body)
.to be_a(Hash)
.and include(error: /File type/)
end
@ -80,7 +80,7 @@ RSpec.describe 'Media API', :attachment_processing do
expect(response)
.to have_http_status(500)
expect(body_as_json)
expect(response.parsed_body)
.to be_a(Hash)
.and include(error: /processing/)
end

View file

@ -26,7 +26,7 @@ RSpec.describe 'Policies' do
subject
expect(response).to have_http_status(200)
expect(body_as_json).to include(
expect(response.parsed_body).to include(
for_not_following: 'accept',
for_not_followers: 'accept',
for_new_accounts: 'accept',
@ -56,7 +56,7 @@ RSpec.describe 'Policies' do
.and change { NotificationPolicy.find_or_initialize_by(account: user.account).for_limited_accounts.to_sym }.from(:filter).to(:drop)
expect(response).to have_http_status(200)
expect(body_as_json).to include(
expect(response.parsed_body).to include(
for_not_following: 'filter',
for_not_followers: 'accept',
for_new_accounts: 'accept',

View file

@ -27,7 +27,7 @@ RSpec.describe 'Search API' do
it 'returns all matching accounts' do
get '/api/v2/search', headers: headers, params: params
expect(body_as_json[:accounts].pluck(:id)).to contain_exactly(bob.id.to_s, ana.id.to_s, tom.id.to_s)
expect(response.parsed_body[:accounts].pluck(:id)).to contain_exactly(bob.id.to_s, ana.id.to_s, tom.id.to_s)
end
context 'with truthy `resolve`' do
@ -80,7 +80,7 @@ RSpec.describe 'Search API' do
it 'returns only the followed accounts' do
get '/api/v2/search', headers: headers, params: params
expect(body_as_json[:accounts].pluck(:id)).to contain_exactly(ana.id.to_s)
expect(response.parsed_body[:accounts].pluck(:id)).to contain_exactly(ana.id.to_s)
end
end
end

View file

@ -22,7 +22,7 @@ RSpec.describe 'Suggestions API' do
expect(response).to have_http_status(200)
expect(body_as_json).to match_array(
expect(response.parsed_body).to match_array(
[bob, jeff].map do |account|
hash_including({
source: 'staff',