From 1393b3de31d95b1aa5122d6da37bd3259830bdb6 Mon Sep 17 00:00:00 2001 From: erdgeist Date: Mon, 6 Jul 2026 16:51:27 +0200 Subject: Fix test to match the current layout --- test/controllers/nodes_controller_test.rb | 126 +++++++++++++++--------------- 1 file changed, 63 insertions(+), 63 deletions(-) (limited to 'test/controllers/nodes_controller_test.rb') diff --git a/test/controllers/nodes_controller_test.rb b/test/controllers/nodes_controller_test.rb index 99e06ae..61f7db4 100644 --- a/test/controllers/nodes_controller_test.rb +++ b/test/controllers/nodes_controller_test.rb @@ -9,13 +9,13 @@ class NodesControllerTest < ActionController::TestCase get :index assert_response :success end - + def test_new login_as :quentin get :new assert_response :success end - + test "create generic node with parent_id provided" do login_as :quentin before_count = Node.count @@ -33,7 +33,7 @@ class NodesControllerTest < ActionController::TestCase assert_equal Node.last.parent_id, Node.root.id assert_equal 1, Node.last.level end - + test "create update node" do login_as :quentin post( @@ -45,7 +45,7 @@ class NodesControllerTest < ActionController::TestCase ) assert_response :redirect end - + test "create top level node" do login_as :quentin before_count = Node.count @@ -62,64 +62,64 @@ class NodesControllerTest < ActionController::TestCase assert_equal expected, Node.last.unique_name assert_equal 1, Node.last.level end - + test "creating a top_level node without a title should not work" do login_as :quentin - + assert_no_difference "Node.count" do post(:create, params: { :kind => "top_level" } ) end end - + test "creating a generic node without a parent_id should not work" do login_as :quentin - + assert_no_difference "Node.count" do post(:create, params: { :kind => "generic" } ) end end - + test "editing a node" do login_as :quentin - + node = Node.find_by_unique_name("fourth_child") node.pages.create node.draft = node.pages.last node.save - + assert_equal 1, node.pages.length - + draft = node.find_or_create_draft( User.first ) draft.title = "Hello" draft.body = "World" draft.save node.publish_draft! - + get :edit, params: { :id => node.id } assert_response :success assert_select("#page_title[value='Hello']") assert_select("#page_body", "World") - + node.reload assert_equal 2, node.pages.length assert_equal "Hello", node.find_or_create_draft( User.first ).title 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, params: { :id => node.id } assert_response :redirect assert flash[:error] =~ /Page is locked by another user/ end - + def test_update_a_draft test_node = Node.root.children.create! :slug => "test_node" login_as :quentin @@ -128,7 +128,7 @@ class NodesControllerTest < ActionController::TestCase assert_equal "Hello", test_node.draft.title assert_equal "There", test_node.draft.body end - + def test_update_a_draft_with_changing_the_template test_node = Node.root.children.create! :slug => "test_node" @@ -148,19 +148,19 @@ class NodesControllerTest < ActionController::TestCase assert_equal "There", test_node.head.body assert_equal "Foobar", test_node.head.template_name end - + test "publish draft with staged_slug unqueal slug" do login_as :quentin - + test_node = Node.root.children.create! :slug => "test_node", :staged_slug => "peter_pan" - + put :publish, params: { :id => test_node.id } - + test_node.reload assert_equal "peter_pan", test_node.slug assert_equal "peter_pan", test_node.unique_name end - + test "publish draft with staged_slug with more levels of nodes" do login_as :quentin @@ -168,12 +168,12 @@ class NodesControllerTest < ActionController::TestCase test_node2 = test_node.children.create! :slug => "test_node2" put :publish, params: { :id => test_node.id } - + test_node.reload; test_node2.reload assert_equal "peter_pan/test_node2", test_node2.unique_name assert_equal "peter_pan", test_node.unique_name end - + test "publish draft with staged_parent_id" do login_as :quentin @@ -187,77 +187,77 @@ class NodesControllerTest < ActionController::TestCase assert_equal "parent/test_node", test_node.unique_name assert_equal "parent/test_node/test_node2", test_node2.unique_name end - + test "publish draft with staged_parent_id and staged_slug" do login_as :quentin - + parent = Node.root.children.create! :slug => "parent" - + test_node = Node.root.children.create!( - :slug => "test_node", + :slug => "test_node", :staged_parent_id => parent.id, :staged_slug => "peter_pan" ) - + test_node2 = test_node.children.create! :slug => "test_node2" - + put :publish, params: { :id => test_node.id } - + test_node.reload; test_node2.reload assert_equal "parent/peter_pan", test_node.unique_name 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, params: { :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, params: { :id => node.id } assert_response :success - assert_select "td", :text => "Test", :count => 3 + assert_select "div.node_content", :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? - + put :unlock, params: { :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 - + put :unlock, params: { :id => node.id } assert_response :redirect assert_equal "Already unlocked", 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 - + test "editing the initial draft sets the author to current_user" do login_as :quentin Node.root.descendants.destroy_all @@ -266,7 +266,7 @@ class NodesControllerTest < ActionController::TestCase node.reload assert_equal "quentin", node.draft.user.login end - + test "updating the author of a node with existing head" do login_as :quentin Node.root.descendants.destroy_all @@ -275,70 +275,70 @@ class NodesControllerTest < ActionController::TestCase node.find_or_create_draft users(:quentin) assert node.draft.valid? assert node.valid? - + put :update, params: { :id => node.id, :page => {:user_id => users(:aaron).id} } assert_response :redirect assert_equal "aaron", node.reload.draft.user.login end - + test "updating an existing page should not modify published_at" do login_as :quentin Node.root.descendants.destroy_all node = create_node_with_published_page - + get :edit, params: { :id => node.id } assert_response :success - + put :publish, params: { :id => node.id } - + node.reload assert_equal node.pages[0].published_at, node.pages[1].published_at end - + test "updating an exisiting page should not alter the author" do login_as :aaron Node.root.descendants.destroy_all node = create_node_with_published_page get :edit, params: { :id => node.id } - + put :publish, params: { :id => node.id } - + node.reload assert_equal node.pages[0].user, node.pages[1].user end - + test "editor and author are the same on a new node" do login_as :quentin node = create_node_with_draft get :edit, params: { :id => node.id } - + node.reload assert_equal "quentin", node.draft.user.login assert_equal "quentin", node.draft.editor.login end - + test "creating new draft alters the editor but keeps the author" do node = create_node_with_published_page assert_equal "quentin", node.head.user.login - + login_as :aaron get :edit, params: {:id => node.id } - + node.reload assert_equal "quentin", node.head.user.login assert_equal "aaron", node.draft.editor.login end - + test "unlocking and relocking changes editor if done by another user" do node = create_node_with_published_page draft = node.find_or_create_draft users(:quentin) assert_equal draft.user.login, draft.editor.login assert node.locked? node.unlock! - + login_as :aaron get :edit, params: { :id => node.id } - + node.reload assert_equal "quentin", node.draft.user.login assert_equal "aaron", node.draft.editor.login -- cgit v1.3