From c7c4b007621fd28c88b65db5fd3296ef730097d9 Mon Sep 17 00:00:00 2001 From: hukl Date: Sat, 17 Oct 2009 23:31:28 +0200 Subject: added some more validations to ensure data integrity and applied necessary changes on tests --- test/functional/content_controller_test.rb | 3 +- test/functional/nodes_controller_test.rb | 102 ++++++++++++++++++++++------- 2 files changed, 78 insertions(+), 27 deletions(-) (limited to 'test/functional') diff --git a/test/functional/content_controller_test.rb b/test/functional/content_controller_test.rb index b76e1d5..4fb3035 100644 --- a/test/functional/content_controller_test.rb +++ b/test/functional/content_controller_test.rb @@ -94,8 +94,7 @@ class ContentControllerTest < ActionController::TestCase protected def create_node_under_root slug - node = Node.create! :slug => slug - node.move_to_child_of Node.root + node = Node.root.children.create! :slug => slug node end diff --git a/test/functional/nodes_controller_test.rb b/test/functional/nodes_controller_test.rb index eca7d93..f8d42da 100644 --- a/test/functional/nodes_controller_test.rb +++ b/test/functional/nodes_controller_test.rb @@ -4,8 +4,7 @@ class NodesControllerTest < ActionController::TestCase def test_get_index Node.root.descendants.delete_all - test_node = Node.create :slug => "foo" - test_node.move_to_child_of Node.root + test_node = Node.root.children.create :slug => "foo" login_as :quentin get :index assert_response :success @@ -111,9 +110,22 @@ class NodesControllerTest < ActionController::TestCase assert_equal "World", node.find_or_create_draft( User.first ).body end + test "editing a locked node raises LockedByAnotherUser Exception" do + login_as :quentin + + node = create_node_with_draft + node.lock_owner = User.last + node.save + + assert node.locked? + + get :edit, :id => node.id + assert_response :redirect + assert @response.flash[:error] =~ /Page is locked by another user/ + end + def test_update_a_draft - test_node = Node.create! :slug => "test_node" - test_node.move_to_child_of Node.root + test_node = Node.root.children.create! :slug => "test_node" login_as :quentin put :update, :id => test_node.id, :page => {:title => "Hello", :body => "There"} @@ -123,8 +135,7 @@ class NodesControllerTest < ActionController::TestCase end def test_update_a_draft_with_changing_the_template - test_node = Node.create! :slug => "test_node" - test_node.move_to_child_of Node.root + test_node = Node.root.children.create! :slug => "test_node" login_as :quentin put :update, { @@ -146,8 +157,7 @@ class NodesControllerTest < ActionController::TestCase test "publish draft with staged_slug unqueal slug" do login_as :quentin - test_node = Node.create! :slug => "test_node", :staged_slug => "peter_pan" - test_node.move_to_child_of Node.root + test_node = Node.root.children.create! :slug => "test_node", :staged_slug => "peter_pan" put :publish, :id => test_node.id @@ -159,10 +169,8 @@ class NodesControllerTest < ActionController::TestCase test "publish draft with staged_slug with more levels of nodes" do login_as :quentin - test_node = Node.create! :slug => "test_node", :staged_slug => "peter_pan" - test_node.move_to_child_of Node.root - test_node2 = Node.create! :slug => "test_node2" - test_node2.move_to_child_of test_node + test_node = Node.root.children.create! :slug => "test_node", :staged_slug => "peter_pan" + test_node2 = test_node.children.create! :slug => "test_node2" put :publish, :id => test_node.id @@ -174,13 +182,10 @@ class NodesControllerTest < ActionController::TestCase test "publish draft with staged_parent_id" do login_as :quentin - parent = Node.create! :slug => "parent" - parent.move_to_child_of Node.root - test_node = Node.create! :slug => "test_node", :staged_parent_id => parent.id - test_node.move_to_child_of Node.root - test_node2 = Node.create! :slug => "test_node2" - test_node2.move_to_child_of test_node - + parent = Node.root.children.create! :slug => "parent" + test_node = Node.root.children.create! :slug => "test_node", :staged_parent_id => parent.id + test_node2 = test_node.children.create! :slug => "test_node2" + put :publish, :id => test_node.id test_node.reload; test_node2.reload @@ -191,18 +196,15 @@ class NodesControllerTest < ActionController::TestCase test "publish draft with staged_parent_id and staged_slug" do login_as :quentin - parent = Node.create! :slug => "parent" - parent.move_to_child_of Node.root + parent = Node.root.children.create! :slug => "parent" - test_node = Node.create!( + test_node = Node.root.children.create!( :slug => "test_node", :staged_parent_id => parent.id, :staged_slug => "peter_pan" ) - test_node.move_to_child_of Node.root - test_node2 = Node.create! :slug => "test_node2" - test_node2.move_to_child_of test_node + test_node2 = test_node.children.create! :slug => "test_node2" put :publish, :id => test_node.id @@ -211,4 +213,54 @@ class NodesControllerTest < ActionController::TestCase assert_equal "parent/peter_pan/test_node2", test_node2.unique_name end + test "show node with empty draft" do + login_as :quentin + assert_not_nil node = create_node_with_draft + get :show, :id => node.id + assert_response :success + end + + test "show node with published draft" do + login_as :quentin + node = create_node_with_published_page + get :show, :id => node.id + assert_response :success + assert_select "td", :text => "Test", :count => 3 + end + + test "unlocking a locked node" do + login_as :quentin + node = create_node_with_published_page + node.find_or_create_draft User.first + + assert node.locked? + + get :unlock, :id => node.id + assert_response :redirect + assert !node.reload.locked? + end + + test "unlocking an already unlocked node" do + login_as :quentin + node = create_node_with_published_page + + get :unlock, :id => node.id + assert_response :redirect + assert_equal "Already unlocked", @response.flash[:notice] + end + + test "updating a node by changing its parent" do + Node.root.descendants.destroy_all + login_as :quentin + node = create_node_with_published_page + node.find_or_create_draft User.first + + other_node = Node.root.children.create( :slug => "other" ) + + node.staged_parent_id = other_node.id + node.publish_draft! + + assert Node.valid? + + end end -- cgit v1.3