diff options
| author | hukl <contact@smyck.org> | 2009-10-20 23:30:39 +0200 |
|---|---|---|
| committer | hukl <contact@smyck.org> | 2009-10-20 23:30:39 +0200 |
| commit | 20056a0e9b4f96680ca0c643166885f65dcd0be7 (patch) | |
| tree | a52396b8781ceacfbc33715d6b360a9bb32a77a7 /test | |
| parent | 8d8b530e2c9f5e2debb2d6abb421187c31733c34 (diff) | |
allow to overwrite the original user in edit view
Diffstat (limited to 'test')
| -rw-r--r-- | test/functional/nodes_controller_test.rb | 27 | ||||
| -rw-r--r-- | test/test_helper.rb | 1 | ||||
| -rw-r--r-- | test/unit/node_test.rb | 25 |
3 files changed, 51 insertions, 2 deletions
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 | |||
| 57 | post( | 57 | post( |
| 58 | :create, | 58 | :create, |
| 59 | :kind => "top_level", | 59 | :kind => "top_level", |
| 60 | :title => "Hello Spaceboy" | 60 | :title => "Hello My Spaceboy" |
| 61 | ) | 61 | ) |
| 62 | end | 62 | end |
| 63 | 63 | ||
| 64 | assert_response :redirect | 64 | assert_response :redirect |
| 65 | expected = "hello-spaceboy" | 65 | expected = "hello-my-spaceboy" |
| 66 | assert_equal expected, Node.last.unique_name | 66 | assert_equal expected, Node.last.unique_name |
| 67 | assert_equal 1, Node.last.level | 67 | assert_equal 1, Node.last.level |
| 68 | end | 68 | end |
| @@ -261,6 +261,29 @@ class NodesControllerTest < ActionController::TestCase | |||
| 261 | node.publish_draft! | 261 | node.publish_draft! |
| 262 | 262 | ||
| 263 | assert Node.valid? | 263 | assert Node.valid? |
| 264 | end | ||
| 265 | |||
| 266 | test "editing the initial draft sets the author to current_user" do | ||
| 267 | login_as :quentin | ||
| 268 | Node.root.descendants.destroy_all | ||
| 269 | node = create_node_with_draft | ||
| 270 | get :edit, :id => node.id | ||
| 271 | assert_equal "quentin", node.draft.user.login | ||
| 272 | end | ||
| 273 | |||
| 274 | test "updating the author of a node with existing head" do | ||
| 275 | login_as :quentin | ||
| 276 | Node.root.descendants.destroy_all | ||
| 277 | node = create_node_with_published_page | ||
| 278 | assert_equal "quentin", node.head.user.login | ||
| 279 | node.find_or_create_draft users(:quentin) | ||
| 280 | assert node.draft.valid? | ||
| 281 | assert node.valid? | ||
| 282 | |||
| 283 | put :update, :id => node.id, :page => {:user_id => users(:aaron).id} | ||
| 284 | assert_response :redirect | ||
| 285 | assert_equal "aaron", node.reload.draft.user.login | ||
| 286 | |||
| 264 | 287 | ||
| 265 | end | 288 | end |
| 266 | end | 289 | 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 | |||
| 45 | draft.title = "Test" | 45 | draft.title = "Test" |
| 46 | draft.abstract = "Test" | 46 | draft.abstract = "Test" |
| 47 | draft.body = "Test" | 47 | draft.body = "Test" |
| 48 | draft.user = users(:quentin) | ||
| 48 | node.publish_draft! | 49 | node.publish_draft! |
| 49 | node | 50 | node |
| 50 | end | 51 | 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 | |||
| 230 | assert_equal 4, test_node.draft.revision | 230 | assert_equal 4, test_node.draft.revision |
| 231 | end | 231 | end |
| 232 | 232 | ||
| 233 | test "a new revision keeps the initial user" do | ||
| 234 | Node.root.descendants.destroy_all | ||
| 235 | node = create_node_with_draft | ||
| 236 | draft = node.draft | ||
| 237 | draft.user = users(:aaron) | ||
| 238 | draft.save | ||
| 239 | node.publish_draft! | ||
| 240 | new_draft = node.find_or_create_draft( users(:quentin) ) | ||
| 241 | assert_equal "aaron", new_draft.user.login | ||
| 242 | end | ||
| 243 | |||
| 244 | test "a new revision can overwrite the initial author" do | ||
| 245 | Node.root.descendants.destroy_all | ||
| 246 | node = create_node_with_draft | ||
| 247 | draft = node.draft | ||
| 248 | draft.user = users(:aaron) | ||
| 249 | draft.save | ||
| 250 | node.publish_draft! | ||
| 251 | new_draft = node.find_or_create_draft( users(:quentin) ) | ||
| 252 | new_draft.user_id = users(:quentin).id | ||
| 253 | new_draft.save | ||
| 254 | node.publish_draft! | ||
| 255 | assert_equal "quentin", node.head.user.login | ||
| 256 | end | ||
| 257 | |||
| 233 | def create_revisions node, count | 258 | def create_revisions node, count |
| 234 | count.times do | 259 | count.times do |
| 235 | node.find_or_create_draft @user1 | 260 | node.find_or_create_draft @user1 |
