diff options
| -rw-r--r-- | app/helpers/nodes_helper.rb | 3 | ||||
| -rw-r--r-- | app/models/node.rb | 6 | ||||
| -rw-r--r-- | app/models/page.rb | 3 | ||||
| -rw-r--r-- | app/views/nodes/edit.html.erb | 4 | ||||
| -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 |
7 files changed, 65 insertions, 4 deletions
diff --git a/app/helpers/nodes_helper.rb b/app/helpers/nodes_helper.rb index 79e75dc..d889719 100644 --- a/app/helpers/nodes_helper.rb +++ b/app/helpers/nodes_helper.rb | |||
| @@ -21,6 +21,9 @@ module NodesHelper | |||
| 21 | Page.custom_templates.map {|x| [x.gsub("_", " ").titlecase, x]} | 21 | Page.custom_templates.map {|x| [x.gsub("_", " ").titlecase, x]} |
| 22 | end | 22 | end |
| 23 | 23 | ||
| 24 | def user_list | ||
| 25 | User.all.map {|u| [u.login, u.id]} | ||
| 26 | end | ||
| 24 | 27 | ||
| 25 | def event_information | 28 | def event_information |
| 26 | if @node.event | 29 | if @node.event |
diff --git a/app/models/node.rb b/app/models/node.rb index db484f9..7a79594 100644 --- a/app/models/node.rb +++ b/app/models/node.rb | |||
| @@ -80,7 +80,7 @@ class Node < ActiveRecord::Base | |||
| 80 | 80 | ||
| 81 | def create_new_draft user | 81 | def create_new_draft user |
| 82 | empty_page = self.pages.create! | 82 | empty_page = self.pages.create! |
| 83 | empty_page.user = user | 83 | empty_page.user = user unless (self.head && self.head.user) |
| 84 | empty_page.save | 84 | empty_page.save |
| 85 | 85 | ||
| 86 | empty_page.clone_attributes_from self.head | 86 | empty_page.clone_attributes_from self.head |
| @@ -159,6 +159,10 @@ class Node < ActiveRecord::Base | |||
| 159 | !children.empty? && !children.first.path_to_root.include?(self.slug) | 159 | !children.empty? && !children.first.path_to_root.include?(self.slug) |
| 160 | end | 160 | end |
| 161 | 161 | ||
| 162 | def head? | ||
| 163 | head_id | ||
| 164 | end | ||
| 165 | |||
| 162 | protected | 166 | protected |
| 163 | def lock_for! current_user | 167 | def lock_for! current_user |
| 164 | self.lock_owner = current_user | 168 | self.lock_owner = current_user |
diff --git a/app/models/page.rb b/app/models/page.rb index 29fcae6..8eeab53 100644 --- a/app/models/page.rb +++ b/app/models/page.rb | |||
| @@ -38,7 +38,7 @@ class Page < ActiveRecord::Base | |||
| 38 | before_save :rewrite_links_in_body | 38 | before_save :rewrite_links_in_body |
| 39 | 39 | ||
| 40 | # Security | 40 | # Security |
| 41 | attr_accessible :title, :abstract, :body, :template_name, :published_at | 41 | attr_accessible :title, :abstract, :body, :template_name, :published_at, :user_id |
| 42 | 42 | ||
| 43 | # Class Methods | 43 | # Class Methods |
| 44 | 44 | ||
| @@ -126,6 +126,7 @@ class Page < ActiveRecord::Base | |||
| 126 | self.tag_list = page.tag_list | 126 | self.tag_list = page.tag_list |
| 127 | self.template_name = page.template_name | 127 | self.template_name = page.template_name |
| 128 | self.published_at = page.published_at | 128 | self.published_at = page.published_at |
| 129 | self.user = page.user | ||
| 129 | 130 | ||
| 130 | # Getting rid of the auto-generated empty translations | 131 | # Getting rid of the auto-generated empty translations |
| 131 | self.globalize_translations.delete_all | 132 | self.globalize_translations.delete_all |
diff --git a/app/views/nodes/edit.html.erb b/app/views/nodes/edit.html.erb index 0063dd9..8e27d0f 100644 --- a/app/views/nodes/edit.html.erb +++ b/app/views/nodes/edit.html.erb | |||
| @@ -55,6 +55,10 @@ | |||
| 55 | <td><%= d.select :template_name, custom_page_templates, {:prompt => 'Select Template'} %></td> | 55 | <td><%= d.select :template_name, custom_page_templates, {:prompt => 'Select Template'} %></td> |
| 56 | </tr> | 56 | </tr> |
| 57 | <tr> | 57 | <tr> |
| 58 | <td class="description">Author</td> | ||
| 59 | <td><%= d.select :user_id, user_list %></td> | ||
| 60 | </tr> | ||
| 61 | <tr> | ||
| 58 | <td class="description">Images</td> | 62 | <td class="description">Images</td> |
| 59 | <td> | 63 | <td> |
| 60 | <ul id="image_box" rel="<%= @draft.id %>"> | 64 | <ul id="image_box" rel="<%= @draft.id %>"> |
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 |
