From baace1fa5df46694ddd515dc3bbca59b22df8692 Mon Sep 17 00:00:00 2001 From: erdgeist Date: Sat, 25 Jul 2026 03:51:44 +0200 Subject: Extract flashes to i18n and stop dispatching on submit labels --- test/controllers/assets_controller_test.rb | 2 +- test/controllers/events_controller_test.rb | 2 +- test/controllers/nodes_controller_test.rb | 10 +++++----- test/controllers/page_translations_controller_test.rb | 4 ++-- test/controllers/users_controller_test.rb | 18 +++++++++--------- 5 files changed, 18 insertions(+), 18 deletions(-) (limited to 'test') diff --git a/test/controllers/assets_controller_test.rb b/test/controllers/assets_controller_test.rb index 4be2e8a1..467e1a68 100644 --- a/test/controllers/assets_controller_test.rb +++ b/test/controllers/assets_controller_test.rb @@ -102,7 +102,7 @@ class AssetsControllerTest < ActionController::TestCase assert_response :redirect asset = Asset.last assert_includes node.draft.assets.reload, asset - assert_match /attached/, flash[:notice] + assert_equal I18n.t("flash.assets.attached", :title => node.title), flash[:notice] end test "create against a foreign-locked node keeps the asset but refuses the attach" do diff --git a/test/controllers/events_controller_test.rb b/test/controllers/events_controller_test.rb index 46f3f4f1..d4fd66d6 100644 --- a/test/controllers/events_controller_test.rb +++ b/test/controllers/events_controller_test.rb @@ -83,7 +83,7 @@ class EventsControllerTest < ActionController::TestCase end assert_redirected_to edit_node_path(node) - assert_equal 'Event was successfully created.', flash[:notice] + assert_equal I18n.t("flash.events.created"), flash[:notice] end test "should not create an event without a title or a node_id" do diff --git a/test/controllers/nodes_controller_test.rb b/test/controllers/nodes_controller_test.rb index 8b59fc37..d7a3abbd 100644 --- a/test/controllers/nodes_controller_test.rb +++ b/test/controllers/nodes_controller_test.rb @@ -91,7 +91,7 @@ class NodesControllerTest < ActionController::TestCase node = Node.last assert_includes node.draft.assets, asset assert_equal asset, node.draft.headline_asset - assert_match /attached/, flash[:notice] + assert_equal I18n.t("flash.nodes.created_with_attachment", :name => "Birth attachment") + " " + I18n.t("flash.common.now_headline"), flash[:notice] end test "the attach notice survives the redirect into the editor" do @@ -104,8 +104,8 @@ class NodesControllerTest < ActionController::TestCase get :edit, params: { :id => Node.last.id } assert_response :success - assert_match /attached/, flash[:notice] - assert_no_match /ready to edit/, flash[:notice] + assert_equal I18n.t("flash.nodes.created_with_attachment", :name => "Flash survivor"), flash[:notice] + assert_not_equal I18n.t("flash.nodes.locked_ready"), flash[:notice] end test "editing a node" do @@ -146,7 +146,7 @@ class NodesControllerTest < ActionController::TestCase get :edit, params: { :id => node.id } assert_response :redirect - assert flash[:error] =~ /Page is locked by another user/ + assert_equal I18n.t("flash.common.locked_by_other"), flash[:error] end def test_update_a_draft @@ -282,7 +282,7 @@ class NodesControllerTest < ActionController::TestCase put :unlock, params: { :id => node.id } assert_response :redirect - assert_equal "Already unlocked", flash[:notice] + assert_equal I18n.t("flash.nodes.already_unlocked"), flash[:notice] end test "updating a node by changing its parent" do diff --git a/test/controllers/page_translations_controller_test.rb b/test/controllers/page_translations_controller_test.rb index feaacd0e..7484a203 100644 --- a/test/controllers/page_translations_controller_test.rb +++ b/test/controllers/page_translations_controller_test.rb @@ -55,7 +55,7 @@ class PageTranslationsControllerTest < ActionController::TestCase delete :destroy, params: { :node_id => node.id, :translation_locale => "en" } - assert_equal "Can't remove the only remaining translation.", flash[:error] + assert_equal I18n.t("flash.page_translations.last_translation"), flash[:error] end test "destroy is a safe no-op, not a false success, when the translation doesn't exist" do @@ -64,7 +64,7 @@ class PageTranslationsControllerTest < ActionController::TestCase delete :destroy, params: { :node_id => node.id, :translation_locale => "en" } - assert_match(/No EN translation exists/, flash[:error]) + assert_equal I18n.t("flash.page_translations.none_to_remove", :lang => "EN"), flash[:error] end test "autosave writes the translation without creating a new revision or touching the draft" do diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb index dcd8f259..67f7c053 100644 --- a/test/controllers/users_controller_test.rb +++ b/test/controllers/users_controller_test.rb @@ -1,7 +1,7 @@ require 'test_helper' class UsersControllerTest < ActionController::TestCase - + test "get index as regular user renders stripped partial" do login_as :quentin get :index @@ -16,20 +16,20 @@ class UsersControllerTest < ActionController::TestCase assert_select "button[type=submit]", I18n.t("admin.common.destroy") assert_select "a", "show" end - + test "get new when logged in as admin" do login_as :aaron get :new assert_response :success end - + test "get new without being logged in as admin redirects back to index" do login_as :quentin get :new assert_response :redirect assert_redirected_to users_path assert_equal( - "Sorry, you need to be an admin for this action", + I18n.t("flash.common.admin_required"), flash[:notice] ) end @@ -84,7 +84,7 @@ class UsersControllerTest < ActionController::TestCase assert_redirected_to users_path assert_equal( - "Sorry, you need to be an admin for this action", + I18n.t("flash.common.admin_required"), flash[:notice] ) end @@ -94,7 +94,7 @@ class UsersControllerTest < ActionController::TestCase get :edit, params: { :id => User.find_by_login("aaron").id } assert_redirected_to users_path assert_equal( - "Sorry, you need to be an admin for this action", + I18n.t("flash.common.admin_required"), flash[:notice] ) end @@ -117,7 +117,7 @@ class UsersControllerTest < ActionController::TestCase put :update, params: { :id => user.id, :user => {:login => "random"} } assert_redirected_to users_path assert_equal( - "Sorry, you need to be an admin for this action", + I18n.t("flash.common.admin_required"), flash[:notice] ) end @@ -137,7 +137,7 @@ class UsersControllerTest < ActionController::TestCase assert_redirected_to user_path(user) assert_equal "random", user.reload.login end - + test "showing a user" do login_as :quentin get :show, params: { :id => User.find_by_login("aaron").id } @@ -151,7 +151,7 @@ class UsersControllerTest < ActionController::TestCase end assert_redirected_to users_path assert_equal( - "Sorry, you need to be an admin for this action", + I18n.t("flash.common.admin_required"), flash[:notice] ) end -- cgit v1.3