From 20056a0e9b4f96680ca0c643166885f65dcd0be7 Mon Sep 17 00:00:00 2001 From: hukl Date: Tue, 20 Oct 2009 23:30:39 +0200 Subject: allow to overwrite the original user in edit view --- test/functional/nodes_controller_test.rb | 27 +++++++++++++++++++++++++-- test/test_helper.rb | 1 + test/unit/node_test.rb | 25 +++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/functional/nodes_controller_test.rb b/test/functional/nodes_controller_test.rb index f8d42da..8710c0b 100644 --- a/test/functional/nodes_controller_test.rb +++ b/test/functional/nodes_controller_test.rb @@ -57,12 +57,12 @@ class NodesControllerTest < ActionController::TestCase post( :create, :kind => "top_level", - :title => "Hello Spaceboy" + :title => "Hello My Spaceboy" ) end assert_response :redirect - expected = "hello-spaceboy" + expected = "hello-my-spaceboy" assert_equal expected, Node.last.unique_name assert_equal 1, Node.last.level end @@ -261,6 +261,29 @@ class NodesControllerTest < ActionController::TestCase 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 + node = create_node_with_draft + get :edit, :id => node.id + 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 + node = create_node_with_published_page + assert_equal "quentin", node.head.user.login + node.find_or_create_draft users(:quentin) + assert node.draft.valid? + assert node.valid? + + put :update, :id => node.id, :page => {:user_id => users(:aaron).id} + assert_response :redirect + assert_equal "aaron", node.reload.draft.user.login + end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 023ed96..cda54bc 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -45,6 +45,7 @@ class ActiveSupport::TestCase draft.title = "Test" draft.abstract = "Test" draft.body = "Test" + draft.user = users(:quentin) node.publish_draft! node end diff --git a/test/unit/node_test.rb b/test/unit/node_test.rb index 92870aa..77e9cad 100644 --- a/test/unit/node_test.rb +++ b/test/unit/node_test.rb @@ -230,6 +230,31 @@ class NodeTest < ActiveSupport::TestCase assert_equal 4, test_node.draft.revision end + test "a new revision keeps the initial user" do + Node.root.descendants.destroy_all + node = create_node_with_draft + draft = node.draft + draft.user = users(:aaron) + draft.save + node.publish_draft! + new_draft = node.find_or_create_draft( users(:quentin) ) + assert_equal "aaron", new_draft.user.login + end + + test "a new revision can overwrite the initial author" do + Node.root.descendants.destroy_all + node = create_node_with_draft + draft = node.draft + draft.user = users(:aaron) + draft.save + node.publish_draft! + new_draft = node.find_or_create_draft( users(:quentin) ) + new_draft.user_id = users(:quentin).id + new_draft.save + node.publish_draft! + assert_equal "quentin", node.head.user.login + end + def create_revisions node, count count.times do node.find_or_create_draft @user1 -- cgit v1.3