summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorerdgeist <erdgeist@erdgeist.org>2026-07-28 00:02:55 +0200
committererdgeist <erdgeist@erdgeist.org>2026-07-28 00:02:55 +0200
commiteca95f90de3de7c6507fc529e00e1e36f136a234 (patch)
treec2ad60e1c3f7ff7969da2e004b245f662a32df4c /test
parent7605ececf7055e6da28eb54160324356c5dfe31c (diff)
Let editors manage menu titles in both locales
Diffstat (limited to 'test')
-rw-r--r--test/controllers/menu_items_controller_test.rb42
-rw-r--r--test/controllers/page_translations_controller_test.rb2
2 files changed, 40 insertions, 4 deletions
diff --git a/test/controllers/menu_items_controller_test.rb b/test/controllers/menu_items_controller_test.rb
index c47467a3..15a7b30b 100644
--- a/test/controllers/menu_items_controller_test.rb
+++ b/test/controllers/menu_items_controller_test.rb
@@ -1,8 +1,44 @@
1require 'test_helper' 1require 'test_helper'
2 2
3class MenuItemsControllerTest < ActionController::TestCase 3class MenuItemsControllerTest < ActionController::TestCase
4 # Replace this with your real tests. 4 def create_menu_item(title = "Ausgangstitel")
5 test "the truth" do 5 item = MenuItem.new(:path => "/menu_title_test")
6 assert true 6 item.titles = { I18n.default_locale.to_s => title }
7 item.save!
8 item
9 end
10
11 test "updating stores a title per locale" do
12 login_as :quentin
13 item = create_menu_item
14
15 patch :update, params: { :id => item.id,
16 :menu_item => { :titles => { "de" => "Transparenz", "en" => "Transparency" } } }
17
18 assert_equal "Transparenz", item.reload.translations.find_by(:locale => "de").title
19 assert_equal "Transparency", item.translations.find_by(:locale => "en").title
20 end
21
22 test "blanking a non-default title falls back to the default locale" do
23 login_as :quentin
24 item = create_menu_item
25 patch :update, params: { :id => item.id,
26 :menu_item => { :titles => { "de" => "Transparenz", "en" => "Transparency" } } }
27
28 patch :update, params: { :id => item.id,
29 :menu_item => { :titles => { "de" => "Transparenz", "en" => "" } } }
30
31 item.reload
32 assert_equal "Transparenz", Globalize.with_locale(:en) { item.title }
33 end
34
35 test "a blank default title is rejected" do
36 login_as :quentin
37 item = create_menu_item
38 patch :update, params: { :id => item.id,
39 :menu_item => { :titles => { "de" => "" } } }
40
41 assert_response :success # re-rendered :edit, not a redirect
42 assert_not_equal "", item.reload.translations.find_by(:locale => "de").title
7 end 43 end
8end 44end
diff --git a/test/controllers/page_translations_controller_test.rb b/test/controllers/page_translations_controller_test.rb
index 7484a203..31eefe84 100644
--- a/test/controllers/page_translations_controller_test.rb
+++ b/test/controllers/page_translations_controller_test.rb
@@ -30,7 +30,7 @@ class PageTranslationsControllerTest < ActionController::TestCase
30 node = Node.root.children.create!(:slug => "translations_exit_test") 30 node = Node.root.children.create!(:slug => "translations_exit_test")
31 node.lock_for_editing!(users(:quentin)) 31 node.lock_for_editing!(users(:quentin))
32 32
33 patch :update, params: { :node_id => node.id, :translation_locale => "en", :page => { :title => "x" }, :commit => "Save + Unlock + Exit" } 33 patch :update, params: { :node_id => node.id, :translation_locale => "en", :page => { :title => "x" }, :unlock_exit => "1" }
34 34
35 assert_nil node.reload.lock_owner 35 assert_nil node.reload.lock_owner
36 assert_redirected_to node_path(node) 36 assert_redirected_to node_path(node)