Use built-in response.parsed_body
for JSON response specs (#31674)
This commit is contained in:
parent
388d5473e1
commit
40f993b3a0
10 changed files with 15 additions and 17 deletions
|
@ -94,7 +94,7 @@ RSpec.describe 'Domain Blocks' do
|
||||||
subject
|
subject
|
||||||
|
|
||||||
expect(response).to have_http_status(200)
|
expect(response).to have_http_status(200)
|
||||||
expect(body_as_json).to eq(
|
expect(body_as_json).to match(
|
||||||
{
|
{
|
||||||
id: domain_block.id.to_s,
|
id: domain_block.id.to_s,
|
||||||
domain: domain_block.domain,
|
domain: domain_block.domain,
|
||||||
|
|
|
@ -26,7 +26,7 @@ describe 'Translation Languages' do
|
||||||
.to have_http_status(200)
|
.to have_http_status(200)
|
||||||
|
|
||||||
expect(body_as_json)
|
expect(body_as_json)
|
||||||
.to eq({ und: %w(en de), en: ['de'] })
|
.to match({ und: %w(en de), en: ['de'] })
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -60,7 +60,7 @@ RSpec.describe 'Lists' do
|
||||||
subject
|
subject
|
||||||
|
|
||||||
expect(response).to have_http_status(200)
|
expect(response).to have_http_status(200)
|
||||||
expect(body_as_json).to eq({
|
expect(body_as_json).to match({
|
||||||
id: list.id.to_s,
|
id: list.id.to_s,
|
||||||
title: list.title,
|
title: list.title,
|
||||||
replies_policy: list.replies_policy,
|
replies_policy: list.replies_policy,
|
||||||
|
@ -144,7 +144,7 @@ RSpec.describe 'Lists' do
|
||||||
expect(response).to have_http_status(200)
|
expect(response).to have_http_status(200)
|
||||||
list.reload
|
list.reload
|
||||||
|
|
||||||
expect(body_as_json).to eq({
|
expect(body_as_json).to match({
|
||||||
id: list.id.to_s,
|
id: list.id.to_s,
|
||||||
title: list.title,
|
title: list.title,
|
||||||
replies_policy: list.replies_policy,
|
replies_policy: list.replies_policy,
|
||||||
|
|
|
@ -133,7 +133,7 @@ RSpec.describe 'Requests' do
|
||||||
subject
|
subject
|
||||||
|
|
||||||
expect(response).to have_http_status(200)
|
expect(response).to have_http_status(200)
|
||||||
expect(body_as_json).to eq({ merged: true })
|
expect(body_as_json).to match({ merged: true })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -146,7 +146,7 @@ RSpec.describe 'Requests' do
|
||||||
subject
|
subject
|
||||||
|
|
||||||
expect(response).to have_http_status(200)
|
expect(response).to have_http_status(200)
|
||||||
expect(body_as_json).to eq({ merged: false })
|
expect(body_as_json).to match({ merged: false })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -22,7 +22,7 @@ RSpec.describe 'Sources' do
|
||||||
subject
|
subject
|
||||||
|
|
||||||
expect(response).to have_http_status(200)
|
expect(response).to have_http_status(200)
|
||||||
expect(body_as_json).to eq({
|
expect(body_as_json).to match({
|
||||||
id: status.id.to_s,
|
id: status.id.to_s,
|
||||||
text: status.text,
|
text: status.text,
|
||||||
spoiler_text: status.spoiler_text,
|
spoiler_text: status.spoiler_text,
|
||||||
|
@ -51,7 +51,7 @@ RSpec.describe 'Sources' do
|
||||||
subject
|
subject
|
||||||
|
|
||||||
expect(response).to have_http_status(200)
|
expect(response).to have_http_status(200)
|
||||||
expect(body_as_json).to eq({
|
expect(body_as_json).to match({
|
||||||
id: status.id.to_s,
|
id: status.id.to_s,
|
||||||
text: status.text,
|
text: status.text,
|
||||||
spoiler_text: status.spoiler_text,
|
spoiler_text: status.spoiler_text,
|
||||||
|
|
|
@ -154,7 +154,7 @@ describe '/api/v1/statuses' do
|
||||||
subject
|
subject
|
||||||
|
|
||||||
expect(response).to have_http_status(422)
|
expect(response).to have_http_status(422)
|
||||||
expect(body_as_json[:unexpected_accounts].map { |a| a.slice(:id, :acct) }).to eq [{ id: bob.id.to_s, acct: bob.acct }]
|
expect(body_as_json[:unexpected_accounts].map { |a| a.slice(:id, :acct) }).to match [{ id: bob.id.to_s, acct: bob.acct }]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@ RSpec.describe 'Filters' do
|
||||||
expect(json[:title]).to eq 'magic'
|
expect(json[:title]).to eq 'magic'
|
||||||
expect(json[:filter_action]).to eq 'hide'
|
expect(json[:filter_action]).to eq 'hide'
|
||||||
expect(json[:context]).to eq ['home']
|
expect(json[:context]).to eq ['home']
|
||||||
expect(json[:keywords].map { |keyword| keyword.slice(:keyword, :whole_word) }).to eq [{ keyword: 'magic', whole_word: true }]
|
expect(json[:keywords].map { |keyword| keyword.slice(:keyword, :whole_word) }).to match [{ keyword: 'magic', whole_word: true }]
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'creates a filter', :aggregate_failures do
|
it 'creates a filter', :aggregate_failures do
|
||||||
|
|
|
@ -235,7 +235,7 @@ RSpec.describe 'Notifications' do
|
||||||
|
|
||||||
expect(response).to have_http_status(200)
|
expect(response).to have_http_status(200)
|
||||||
expect(body_as_json[:partial_accounts].size).to be > 0
|
expect(body_as_json[:partial_accounts].size).to be > 0
|
||||||
expect(body_as_json[:partial_accounts][0].keys).to contain_exactly(:acct, :avatar, :avatar_static, :bot, :id, :locked, :url)
|
expect(body_as_json[:partial_accounts][0].keys.map(&:to_sym)).to contain_exactly(:acct, :avatar, :avatar_static, :bot, :id, :locked, :url)
|
||||||
expect(body_as_json[:partial_accounts].pluck(:id)).to_not include(recent_account.id.to_s)
|
expect(body_as_json[:partial_accounts].pluck(:id)).to_not include(recent_account.id.to_s)
|
||||||
expect(body_as_json[:accounts].pluck(:id)).to include(recent_account.id.to_s)
|
expect(body_as_json[:accounts].pluck(:id)).to include(recent_account.id.to_s)
|
||||||
end
|
end
|
||||||
|
|
|
@ -39,11 +39,7 @@ RSpec.configure do |config|
|
||||||
end
|
end
|
||||||
|
|
||||||
def body_as_json
|
def body_as_json
|
||||||
json_str_to_hash(response.body)
|
response.parsed_body
|
||||||
end
|
|
||||||
|
|
||||||
def json_str_to_hash(str)
|
|
||||||
JSON.parse(str, symbolize_names: true)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def serialized_record_json(record, serializer, adapter: nil)
|
def serialized_record_json(record, serializer, adapter: nil)
|
||||||
|
|
|
@ -9,7 +9,9 @@ end
|
||||||
|
|
||||||
RSpec::Matchers.define :match_json_values do |values|
|
RSpec::Matchers.define :match_json_values do |values|
|
||||||
match do |string|
|
match do |string|
|
||||||
expect(json_str_to_hash(string))
|
parsed_json = JSON.parse(string, symbolize_names: true)
|
||||||
|
|
||||||
|
expect(parsed_json)
|
||||||
.to include(values)
|
.to include(values)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue