FIX: Failed to save email template with pluralized subject

This commit is contained in:
Gerhard Schlager 2019-03-06 16:49:40 +01:00
parent 5cf63e43c6
commit 4000978452
2 changed files with 20 additions and 2 deletions

View File

@ -113,12 +113,15 @@ class Admin::EmailTemplatesController < Admin::AdminController
def update_key(key, value) def update_key(key, value)
old_value = I18n.t(key) old_value = I18n.t(key)
translation_override = TranslationOverride.upsert!(I18n.locale, key, value)
unless old_value.is_a?(Hash)
translation_override = TranslationOverride.upsert!(I18n.locale, key, value)
end
{ {
key: key, key: key,
old_value: old_value, old_value: old_value,
error_messages: translation_override.errors.full_messages error_messages: translation_override&.errors&.full_messages
} }
end end

View File

@ -214,6 +214,21 @@ RSpec.describe Admin::EmailTemplatesController do
end end
end end
context "when subject has plural keys" do
it "doesn't update the subject" do
old_subject = I18n.t('system_messages.pending_users_reminder.subject_template')
expect(old_subject).to be_a(Hash)
put '/admin/customize/email_templates/system_messages.pending_users_reminder', params: {
email_template: { subject: '', body: 'Lorem ipsum' }
}, headers: headers
expect(response.status).to eq(200)
expect(I18n.t('system_messages.pending_users_reminder.subject_template')).to eq(old_subject)
expect(I18n.t('system_messages.pending_users_reminder.text_body_template')).to eq('Lorem ipsum')
end
end
end end
end end