FIX: Failed to save email template with pluralized subject

FIX: Failed to save email template with pluralized subject

diff --git a/app/controllers/admin/email_templates_controller.rb b/app/controllers/admin/email_templates_controller.rb
index f36fa25..aa9eef4 100644
--- a/app/controllers/admin/email_templates_controller.rb
+++ b/app/controllers/admin/email_templates_controller.rb
@@ -113,12 +113,15 @@ class Admin::EmailTemplatesController < Admin::AdminController
 
   def update_key(key, value)
     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,
       old_value: old_value,
-      error_messages: translation_override.errors.full_messages
+      error_messages: translation_override&.errors&.full_messages
     }
   end
 
diff --git a/spec/requests/admin/email_templates_controller_spec.rb b/spec/requests/admin/email_templates_controller_spec.rb
index 150112d..b0d3a0a 100644
--- a/spec/requests/admin/email_templates_controller_spec.rb
+++ b/spec/requests/admin/email_templates_controller_spec.rb
@@ -214,6 +214,21 @@ RSpec.describe Admin::EmailTemplatesController do
         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

GitHub sha: 40009784

1 Like

This commit has been mentioned on Discourse Meta. There might be relevant details there: