summaryrefslogtreecommitdiff
path: root/test/controllers/nodes_controller_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/controllers/nodes_controller_test.rb')
-rw-r--r--test/controllers/nodes_controller_test.rb51
1 files changed, 32 insertions, 19 deletions
diff --git a/test/controllers/nodes_controller_test.rb b/test/controllers/nodes_controller_test.rb
index 745ae4e0..c7caeed1 100644
--- a/test/controllers/nodes_controller_test.rb
+++ b/test/controllers/nodes_controller_test.rb
@@ -193,7 +193,8 @@ class NodesControllerTest < ActionController::TestCase
193 test "publish draft with staged_slug unqueal slug" do 193 test "publish draft with staged_slug unqueal slug" do
194 login_as :quentin 194 login_as :quentin
195 195
196 test_node = Node.root.children.create! :slug => "test_node", :staged_slug => "peter_pan" 196 test_node = Node.root.children.create!(:slug => "test_node")
197 test_node.draft.update!(:slug => "peter_pan")
197 198
198 put :publish, params: { :id => test_node.id } 199 put :publish, params: { :id => test_node.id }
199 200
@@ -205,7 +206,8 @@ class NodesControllerTest < ActionController::TestCase
205 test "publish draft with staged_slug with more levels of nodes" do 206 test "publish draft with staged_slug with more levels of nodes" do
206 login_as :quentin 207 login_as :quentin
207 208
208 test_node = Node.root.children.create! :slug => "test_node", :staged_slug => "peter_pan" 209 test_node = Node.root.children.create!(:slug => "test_node")
210 test_node.draft.update!(:slug => "peter_pan")
209 test_node2 = test_node.children.create! :slug => "test_node2" 211 test_node2 = test_node.children.create! :slug => "test_node2"
210 212
211 put :publish, params: { :id => test_node.id } 213 put :publish, params: { :id => test_node.id }
@@ -215,12 +217,13 @@ class NodesControllerTest < ActionController::TestCase
215 assert_equal "peter_pan", test_node.unique_name 217 assert_equal "peter_pan", test_node.unique_name
216 end 218 end
217 219
218 test "publish draft with staged_parent_id" do 220 test "publish draft with a moved parent" do
219 login_as :quentin 221 login_as :quentin
220 222
221 parent = Node.root.children.create! :slug => "parent" 223 parent = Node.root.children.create!(:slug => "parent")
222 test_node = Node.root.children.create! :slug => "test_node", :staged_parent_id => parent.id 224 test_node = Node.root.children.create!(:slug => "test_node")
223 test_node2 = test_node.children.create! :slug => "test_node2" 225 test_node.draft.update!(:parent_node_id => parent.id)
226 test_node2 = test_node.children.create!(:slug => "test_node2")
224 227
225 put :publish, params: { :id => test_node.id } 228 put :publish, params: { :id => test_node.id }
226 229
@@ -229,18 +232,13 @@ class NodesControllerTest < ActionController::TestCase
229 assert_equal "parent/test_node/test_node2", test_node2.unique_name 232 assert_equal "parent/test_node/test_node2", test_node2.unique_name
230 end 233 end
231 234
232 test "publish draft with staged_parent_id and staged_slug" do 235 test "publish draft with a moved parent and a renamed slug" do
233 login_as :quentin 236 login_as :quentin
234 237
235 parent = Node.root.children.create! :slug => "parent" 238 parent = Node.root.children.create!(:slug => "parent")
236 239 test_node = Node.root.children.create!(:slug => "test_node")
237 test_node = Node.root.children.create!( 240 test_node.draft.update!(:parent_node_id => parent.id, :slug => "peter_pan")
238 :slug => "test_node", 241 test_node2 = test_node.children.create!(:slug => "test_node2")
239 :staged_parent_id => parent.id,
240 :staged_slug => "peter_pan"
241 )
242
243 test_node2 = test_node.children.create! :slug => "test_node2"
244 242
245 put :publish, params: { :id => test_node.id } 243 put :publish, params: { :id => test_node.id }
246 244
@@ -293,7 +291,7 @@ class NodesControllerTest < ActionController::TestCase
293 291
294 other_node = Node.root.children.create( :slug => "other" ) 292 other_node = Node.root.children.create( :slug => "other" )
295 293
296 node.staged_parent_id = other_node.id 294 node.draft.update!(:parent_node_id => other_node.id)
297 node.publish_draft! 295 node.publish_draft!
298 296
299 assert Node.valid? 297 assert Node.valid?
@@ -711,18 +709,33 @@ class NodesControllerTest < ActionController::TestCase
711 assert flash[:error].present? 709 assert flash[:error].present?
712 end 710 end
713 711
714 test "restore_from_trash reparents to the given parent" do 712 test "restore_from_trash reparents to the 'old' parent" do
715 login_as :quentin 713 login_as :quentin
716 node = Node.root.children.create!(:slug => "restore_me") 714 node = Node.root.children.create!(:slug => "restore_me")
717 node.trash!(users(:quentin)) 715 node.trash!(users(:quentin))
718 target = Node.root.children.create!(:slug => "restore_home") 716 target = Node.root.children.create!(:slug => "restore_home")
719 717
720 put :restore_from_trash, params: { :id => node.id, :parent_id => target.id } 718 node.reload.draft.update!(:parent_node_id => target.id)
719 put :restore_from_trash, params: { :locale => "de", :id => node.id }
721 720
722 assert_redirected_to node_path(node) 721 assert_redirected_to node_path(node)
723 assert_equal target, node.reload.parent 722 assert_equal target, node.reload.parent
724 end 723 end
725 724
725 test "restore_from_trash follows an explicitly chosen parent" do
726 login_as :quentin
727 node = Node.root.children.create!(:slug => "restore_pick")
728 node.trash!(users(:quentin))
729 chosen = Node.root.children.create!(:slug => "chosen_home")
730
731 put :restore_from_trash, params: { :locale => "de", :id => node.id,
732 :parent_id => chosen.id }
733
734 assert_equal chosen, node.reload.parent
735 assert_equal chosen.id, node.draft.parent_node_id,
736 "the choice is recorded on the draft, not applied behind its back"
737 end
738
726 test "destroy refuses a node outside the Trash" do 739 test "destroy refuses a node outside the Trash" do
727 login_as :quentin 740 login_as :quentin
728 node = Node.root.children.create!(:slug => "not_deletable_here") 741 node = Node.root.children.create!(:slug => "not_deletable_here")