Different fix (#7815)

This commit is contained in:
Osama Sayegh
2019-07-02 04:53:16 +03:00
committed by Sam
parent 4dcc5f16f1
commit f1c67729de
10 changed files with 78 additions and 12 deletions

View File

@ -40,6 +40,29 @@ RSpec.describe Admin::EmailTemplatesController do
json = ::JSON.parse(response.body)
expect(json['email_templates']).to be_present
end
it 'returns overridden = true if subject or body has translation_overrides record' do
sign_in(admin)
put '/admin/customize/email_templates/user_notifications.admin_login', params: {
email_template: { subject: original_subject, body: original_body }
}, headers: headers
expect(response.status).to eq(200)
get '/admin/customize/email_templates.json'
expect(response.status).to eq(200)
templates = JSON.parse(response.body)['email_templates']
template = templates.find { |t| t['id'] == 'user_notifications.admin_login' }
expect(template['can_revert']).to eq(true)
TranslationOverride.destroy_all
get '/admin/customize/email_templates.json'
expect(response.status).to eq(200)
templates = JSON.parse(response.body)['email_templates']
template = templates.find { |t| t['id'] == 'user_notifications.admin_login' }
expect(template['can_revert']).to eq(false)
end
end
context "#update" do
@ -142,7 +165,7 @@ RSpec.describe Admin::EmailTemplatesController do
include_examples "invalid email template"
end
context "when subject and body are invalid invalid" do
context "when subject and body are invalid" do
let(:email_subject) { 'Subject with %{invalid} interpolation key' }
let(:email_body) { 'Body with some invalid interpolation keys: %{invalid}' }

View File

@ -177,6 +177,26 @@ RSpec.describe Admin::SiteTextsController do
expect(response.status).to eq(404)
end
it 'returns overridden = true if there is a translation_overrides record for the key' do
key = 'js.topic.list'
put "/admin/customize/site_texts/#{key}.json", params: {
site_text: { value: I18n.t(key) }
}
expect(response.status).to eq(200)
get "/admin/customize/site_texts/#{key}.json"
expect(response.status).to eq(200)
json = JSON.parse(response.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)
expect(json['site_text']['overridden']).to eq(false)
end
context 'plural keys' do
before do
I18n.backend.store_translations(:en, colour: { one: '%{count} colour', other: '%{count} colours' })