]> git.openstreetmap.org Git - rails.git/commitdiff
Ensure that flash message is shown in the updated language
authorAndy Allan <git@gravitystorm.co.uk>
Wed, 21 Jul 2021 17:44:24 +0000 (18:44 +0100)
committerAndy Allan <git@gravitystorm.co.uk>
Wed, 21 Jul 2021 17:58:47 +0000 (18:58 +0100)
app/controllers/preferences_controller.rb
app/views/preferences/_update_success_flash.html.erb [new file with mode: 0644]
config/locales/en.yml
test/system/preferences_test.rb [new file with mode: 0644]

index 6839bf37a8058302907fb700a832ad293f406854..e098a8acc49a989a58b390e1cfb3a27570e23d95 100644 (file)
@@ -22,7 +22,8 @@ class PreferencesController < ApplicationController
                                       params[:user][:preferred_editor]
                                     end
     if current_user.save
-      flash[:notice] = t ".success"
+      # Use a partial so that it is rendered during the next page load in the correct language.
+      flash[:notice] = { :partial => "preferences/update_success_flash" }
       redirect_to preferences_path
     else
       flash[:error] = t ".failure"
diff --git a/app/views/preferences/_update_success_flash.html.erb b/app/views/preferences/_update_success_flash.html.erb
new file mode 100644 (file)
index 0000000..8fd1095
--- /dev/null
@@ -0,0 +1 @@
+<%= t ".message" %>
index 1ef7db9c4a597264dc7fee618432494390310571..fcfb2bc89533a5c3e603178fbbbbbd7375b24b9e 100644 (file)
@@ -1655,8 +1655,9 @@ en:
       save: Update Preferences
       cancel: Cancel
     update:
-      success: Preferences updated.
       failure: Couldn't update preferences.
+    update_success_flash:
+      message: Preferences updated.
   profiles:
     edit:
       title: Edit Profile
diff --git a/test/system/preferences_test.rb b/test/system/preferences_test.rb
new file mode 100644 (file)
index 0000000..e5bcd10
--- /dev/null
@@ -0,0 +1,23 @@
+require "application_system_test_case"
+
+class PreferencesTest < ApplicationSystemTestCase
+  def test_flash_message_shows_in_original_language
+    sign_in_as(create(:user))
+
+    visit edit_preferences_path
+    click_on "Update Preferences"
+
+    assert page.has_content?("Preferences updated")
+  end
+
+  def test_flash_message_shows_in_new_language
+    sign_in_as(create(:user))
+
+    visit edit_preferences_path
+    fill_in "Preferred Languages", :with => "fr"
+    click_on "Update Preferences"
+
+    # TODO: enable with french translation when that's available
+    # assert page.has_content?("Préférences mises à jour") # rubocop:disable Style/AsciiComments
+  end
+end