mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 06:41:25 +08:00
DEV: Use response.parsed_body
in specs (#9615)
Most of it was autofixed with rubocop-discourse 2.1.1.
This commit is contained in:
@ -48,35 +48,35 @@ RSpec.describe Admin::SiteTextsController do
|
||||
it 'returns json' do
|
||||
get "/admin/customize/site_texts.json", params: { q: 'title' }
|
||||
expect(response.status).to eq(200)
|
||||
expect(JSON.parse(response.body)['site_texts']).to include(include("id" => "title"))
|
||||
expect(response.parsed_body['site_texts']).to include(include("id" => "title"))
|
||||
end
|
||||
|
||||
it 'sets has_more to true if more than 50 results were found' do
|
||||
get "/admin/customize/site_texts.json", params: { q: 'e' }
|
||||
expect(response.status).to eq(200)
|
||||
expect(JSON.parse(response.body)['site_texts'].size).to eq(50)
|
||||
expect(JSON.parse(response.body)['extras']['has_more']).to be_truthy
|
||||
expect(response.parsed_body['site_texts'].size).to eq(50)
|
||||
expect(response.parsed_body['extras']['has_more']).to be_truthy
|
||||
end
|
||||
|
||||
it 'works with pages' do
|
||||
texts = Set.new
|
||||
|
||||
get "/admin/customize/site_texts.json", params: { q: 'e' }
|
||||
JSON.parse(response.body)['site_texts'].each { |text| texts << text['id'] }
|
||||
response.parsed_body['site_texts'].each { |text| texts << text['id'] }
|
||||
expect(texts.size).to eq(50)
|
||||
|
||||
get "/admin/customize/site_texts.json", params: { q: 'e', page: 1 }
|
||||
JSON.parse(response.body)['site_texts'].each { |text| texts << text['id'] }
|
||||
response.parsed_body['site_texts'].each { |text| texts << text['id'] }
|
||||
expect(texts.size).to eq(100)
|
||||
end
|
||||
|
||||
it 'works with locales' do
|
||||
get "/admin/customize/site_texts.json", params: { q: 'yes_value', locale: 'en' }
|
||||
value = JSON.parse(response.body)['site_texts'].find { |text| text['id'] == 'js.yes_value' }['value']
|
||||
value = response.parsed_body['site_texts'].find { |text| text['id'] == 'js.yes_value' }['value']
|
||||
expect(value).to eq(I18n.with_locale(:en) { I18n.t('js.yes_value') })
|
||||
|
||||
get "/admin/customize/site_texts.json", params: { q: 'yes_value', locale: 'de' }
|
||||
value = JSON.parse(response.body)['site_texts'].find { |text| text['id'] == 'js.yes_value' }['value']
|
||||
value = response.parsed_body['site_texts'].find { |text| text['id'] == 'js.yes_value' }['value']
|
||||
expect(value).to eq(I18n.with_locale(:de) { I18n.t('js.yes_value') })
|
||||
end
|
||||
|
||||
@ -99,7 +99,7 @@ RSpec.describe Admin::SiteTextsController do
|
||||
].each do |search_term|
|
||||
get "/admin/customize/site_texts.json", params: { q: search_term }
|
||||
expect(response.status).to eq(200)
|
||||
expect(JSON.parse(response.body)['site_texts']).to include(include("id" => "title", "value" => value))
|
||||
expect(response.parsed_body['site_texts']).to include(include("id" => "title", "value" => value))
|
||||
end
|
||||
end
|
||||
|
||||
@ -114,7 +114,7 @@ RSpec.describe Admin::SiteTextsController do
|
||||
].each do |search_term|
|
||||
get "/admin/customize/site_texts.json", params: { q: search_term }
|
||||
expect(response.status).to eq(200)
|
||||
expect(JSON.parse(response.body)['site_texts']).to include(include("id" => "embed.loading", "value" => value))
|
||||
expect(response.parsed_body['site_texts']).to include(include("id" => "embed.loading", "value" => value))
|
||||
end
|
||||
end
|
||||
|
||||
@ -125,11 +125,11 @@ RSpec.describe Admin::SiteTextsController do
|
||||
|
||||
get "/admin/customize/site_texts.json", params: { q: 'missing_plural_key' }
|
||||
expect(response.status).to eq(200)
|
||||
expect(JSON.parse(response.body)['site_texts']).to be_empty
|
||||
expect(response.parsed_body['site_texts']).to be_empty
|
||||
|
||||
get "/admin/customize/site_texts.json", params: { q: 'another_missing_key' }
|
||||
expect(response.status).to eq(200)
|
||||
expect(JSON.parse(response.body)['site_texts']).to be_empty
|
||||
expect(response.parsed_body['site_texts']).to be_empty
|
||||
end
|
||||
|
||||
context 'plural keys' do
|
||||
@ -205,7 +205,7 @@ RSpec.describe Admin::SiteTextsController do
|
||||
get "/admin/customize/site_texts/js.topic.list.json"
|
||||
expect(response.status).to eq(200)
|
||||
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
|
||||
site_text = json['site_text']
|
||||
|
||||
@ -217,7 +217,7 @@ RSpec.describe Admin::SiteTextsController do
|
||||
get "/admin/customize/site_texts/js.emoji_picker.food_&_drink.json"
|
||||
expect(response.status).to eq(200)
|
||||
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
|
||||
site_text = json['site_text']
|
||||
|
||||
@ -239,14 +239,14 @@ RSpec.describe Admin::SiteTextsController do
|
||||
|
||||
get "/admin/customize/site_texts/#{key}.json"
|
||||
expect(response.status).to eq(200)
|
||||
json = JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
expect(json['site_text']['overridden']).to eq(true)
|
||||
|
||||
TranslationOverride.destroy_all
|
||||
|
||||
get "/admin/customize/site_texts/#{key}.json"
|
||||
expect(response.status).to eq(200)
|
||||
json = JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
expect(json['site_text']['overridden']).to eq(false)
|
||||
end
|
||||
|
||||
@ -265,7 +265,7 @@ RSpec.describe Admin::SiteTextsController do
|
||||
get "/admin/customize/site_texts/#{id}.json"
|
||||
expect(response.status).to eq(200)
|
||||
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
expect(json).to be_present
|
||||
|
||||
site_text = json['site_text']
|
||||
@ -312,7 +312,7 @@ RSpec.describe Admin::SiteTextsController do
|
||||
|
||||
expect(response.status).to eq(404)
|
||||
|
||||
json = JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
expect(json['error_type']).to eq('not_found')
|
||||
end
|
||||
|
||||
@ -323,7 +323,7 @@ RSpec.describe Admin::SiteTextsController do
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
site_text = json['site_text']
|
||||
|
||||
expect(site_text['id']).to eq('js.emoji_picker.animals_&_nature')
|
||||
@ -337,7 +337,7 @@ RSpec.describe Admin::SiteTextsController do
|
||||
|
||||
expect(response.status).to eq(403)
|
||||
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
expect(json['error_type']).to eq('invalid_access')
|
||||
expect(json['errors'].size).to eq(1)
|
||||
expect(json['errors'].first).to eq(I18n.t('email_template_cant_be_modified'))
|
||||
@ -352,7 +352,7 @@ RSpec.describe Admin::SiteTextsController do
|
||||
|
||||
expect(response.status).to eq(422)
|
||||
|
||||
body = JSON.parse(response.body)
|
||||
body = response.parsed_body
|
||||
|
||||
expect(body['message']).to eq(I18n.t(
|
||||
'activerecord.errors.models.translation_overrides.attributes.value.invalid_interpolation_keys',
|
||||
@ -390,7 +390,7 @@ RSpec.describe Admin::SiteTextsController do
|
||||
put "/admin/customize/site_texts/title.json", params: { site_text: { value: 'hello' } }
|
||||
expect(response.status).to eq(200)
|
||||
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
|
||||
site_text = json['site_text']
|
||||
|
||||
@ -401,7 +401,7 @@ RSpec.describe Admin::SiteTextsController do
|
||||
delete "/admin/customize/site_texts/title.json"
|
||||
expect(response.status).to eq(200)
|
||||
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
|
||||
site_text = json['site_text']
|
||||
|
||||
@ -422,24 +422,24 @@ RSpec.describe Admin::SiteTextsController do
|
||||
|
||||
get "/admin/customize/site_texts/title.json"
|
||||
expect(response.status).to eq(200)
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
expect(json['site_text']['value']).to eq(ru_title)
|
||||
|
||||
get "/admin/customize/site_texts/js.topic.read_more_MF.json"
|
||||
expect(response.status).to eq(200)
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
expect(json['site_text']['value']).to eq(ru_mf_text)
|
||||
|
||||
SiteSetting.default_locale = :en
|
||||
|
||||
get "/admin/customize/site_texts/title.json"
|
||||
expect(response.status).to eq(200)
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
expect(json['site_text']['value']).to_not eq(ru_title)
|
||||
|
||||
get "/admin/customize/site_texts/js.topic.read_more_MF.json"
|
||||
expect(response.status).to eq(200)
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
expect(json['site_text']['value']).to_not eq(ru_mf_text)
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user