From 37c542bee952193ebfbced8529b8699e2712fdc8 Mon Sep 17 00:00:00 2001 From: erdgeist Date: Thu, 30 Jul 2026 16:50:19 +0200 Subject: Localise model validation messages and refusal reasons --- test/controllers/nodes_controller_test.rb | 2 +- test/models/node_test.rb | 17 +++++++++++++++++ test/models/related_asset_test.rb | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/controllers/nodes_controller_test.rb b/test/controllers/nodes_controller_test.rb index d7a3abbd..0b6e65ee 100644 --- a/test/controllers/nodes_controller_test.rb +++ b/test/controllers/nodes_controller_test.rb @@ -628,7 +628,7 @@ class NodesControllerTest < ActionController::TestCase test "chapters renders the curated heading" do login_as :quentin get :chapters - assert_select "h1", "Chapters" + assert_select "h1", "Dezentrale" end test "sitemap collapses configured paths but leaves others open" do diff --git a/test/models/node_test.rb b/test/models/node_test.rb index c5b0d6a2..c1316ea6 100644 --- a/test/models/node_test.rb +++ b/test/models/node_test.rb @@ -919,4 +919,21 @@ class NodeTest < ActiveSupport::TestCase node.reload assert_raises(ActiveRecord::RecordInvalid) { node.publish_draft! } end + + test "refusals localise their message rather than hardcoding it" do + trash = Node.trash + + I18n.with_locale(:de) do + error = assert_raises(ActiveRecord::RecordInvalid) { trash.trash! } + assert_includes error.message, + I18n.t("activerecord.errors.models.node.attributes.base.trash_the_trash") + end + + I18n.with_locale(:en) do + trash.errors.clear + error = assert_raises(ActiveRecord::RecordInvalid) { trash.trash! } + assert_includes error.message, + I18n.t("activerecord.errors.models.node.attributes.base.trash_the_trash") + end + end end diff --git a/test/models/related_asset_test.rb b/test/models/related_asset_test.rb index bb86ddbb..ea7c3d35 100644 --- a/test/models/related_asset_test.rb +++ b/test/models/related_asset_test.rb @@ -29,7 +29,7 @@ class RelatedAssetTest < ActiveSupport::TestCase related.headline = true assert_not related.valid? - assert_includes related.errors[:headline], "can only be set on image or PDF assets" + assert_includes related.errors[:headline], I18n.t("activerecord.errors.models.related_asset.attributes.headline.images_and_pdfs_only") end test "the headline validation does not raise when asset is missing" do -- cgit v1.3