summaryrefslogtreecommitdiff
path: root/test/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'test/controllers')
-rw-r--r--test/controllers/page_translations_controller_test.rb78
1 files changed, 78 insertions, 0 deletions
diff --git a/test/controllers/page_translations_controller_test.rb b/test/controllers/page_translations_controller_test.rb
new file mode 100644
index 0000000..d84ac45
--- /dev/null
+++ b/test/controllers/page_translations_controller_test.rb
@@ -0,0 +1,78 @@
1require 'test_helper'
2
3class PageTranslationsControllerTest < ActionController::TestCase
4 test "index lists the default locale's existing translation and flags a missing one" do
5 login_as :quentin
6 node = Node.root.children.create!(:slug => "translations_index_test")
7 node.publish_draft!
8
9 get :index, params: { :node_id => node.id }
10
11 assert_response :success
12 assert_equal [:en], assigns(:translations).map { |t| t[:locale] }
13 assert_equal false, assigns(:translations).first[:exists]
14 end
15
16 test "update creates a first-time translation on a fresh draft, leaving head untouched" do
17 login_as :quentin
18 node = Node.root.children.create!(:slug => "translations_create_test")
19 Globalize.with_locale(:de) { node.draft.update!(:title => "Deutscher Titel") }
20 node.publish_draft!
21
22 patch :update, params: { :node_id => node.id, :translation_locale => "en", :page => { :title => "English Title" } }
23
24 node.reload
25 assert_not_nil node.draft
26 assert_includes node.draft.translated_locales, :en
27 assert_not_includes node.head.translated_locales, :en
28 end
29
30 test "no route exists for the default locale under the translations resource" do
31 login_as :quentin
32 node = Node.root.children.create!(:slug => "translations_route_constraint_test")
33
34 assert_raises(ActionController::UrlGenerationError) do
35 patch :update, params: { :node_id => node.id, :translation_locale => "de", :page => { :title => "x" } }
36 end
37 end
38
39 test "update with Save + Unlock + Exit unlocks the node and redirects to nodes#show" do
40 login_as :quentin
41 node = Node.root.children.create!(:slug => "translations_exit_test")
42
43 patch :update, params: { :node_id => node.id, :translation_locale => "en", :page => { :title => "x" }, :commit => "Save + Unlock + Exit" }
44
45 assert_nil node.reload.lock_owner
46 assert_redirected_to node_path(node)
47 end
48
49 test "update saves the translation onto the draft" do
50 login_as :quentin
51 node = Node.root.children.create!(:slug => "translations_update_test")
52 Globalize.with_locale(:en) { node.draft.update!(:title => "Original") }
53
54 patch :update, params: { :node_id => node.id, :translation_locale => "en", :page => { :title => "Revised" } }
55
56 assert_equal "Revised", Globalize.with_locale(:en) { node.draft.reload.title }
57 end
58
59 test "destroy refuses to remove the only remaining translation" do
60 login_as :quentin
61 node = Node.root.children.create!(:slug => "translations_destroy_last_test")
62 Globalize.with_locale(:en) { node.draft.update!(:title => "Only translation") }
63 node.draft.translations.where(:locale => :de).delete_all
64
65 delete :destroy, params: { :node_id => node.id, :translation_locale => "en" }
66
67 assert_equal "Can't remove the only remaining translation.", flash[:error]
68 end
69
70 test "destroy is a safe no-op, not a false success, when the translation doesn't exist" do
71 login_as :quentin
72 node = Node.root.children.create!(:slug => "translations_destroy_missing_test")
73
74 delete :destroy, params: { :node_id => node.id, :translation_locale => "en" }
75
76 assert_match(/No EN translation exists/, flash[:error])
77 end
78end