diff options
| author | hukl <contact@smyck.org> | 2009-03-01 13:56:24 +0100 |
|---|---|---|
| committer | hukl <contact@smyck.org> | 2009-03-01 13:56:24 +0100 |
| commit | c7757522c2750675fab6c4324453e237b863d84c (patch) | |
| tree | 3cc50a7f8e5c5ab9dbad1957863422a772dddf14 /test/unit/node_test.rb | |
| parent | 62db596a0807059afe321930c2015b30f8b0e6d9 (diff) | |
refactored drafts which are now identified by a draft_id on the node rather than by guessing it. i was really that close to make that mistake again.
Diffstat (limited to 'test/unit/node_test.rb')
| -rw-r--r-- | test/unit/node_test.rb | 55 |
1 files changed, 45 insertions, 10 deletions
diff --git a/test/unit/node_test.rb b/test/unit/node_test.rb index 549cccd..2558ca3 100644 --- a/test/unit/node_test.rb +++ b/test/unit/node_test.rb | |||
| @@ -11,6 +11,21 @@ class NodeTest < ActiveSupport::TestCase | |||
| 11 | @user2 = User.create :login => 'show', :email => "f@b.com", :password => 'foobar', :password_confirmation => 'foobar' | 11 | @user2 = User.create :login => 'show', :email => "f@b.com", :password => 'foobar', :password_confirmation => 'foobar' |
| 12 | end | 12 | end |
| 13 | 13 | ||
| 14 | def test_returning_existing_drafts | ||
| 15 | test_node = Node.create! :slug => "test_node" | ||
| 16 | test_node.move_to_child_of Node.root | ||
| 17 | |||
| 18 | assert_not_nil test_node.draft | ||
| 19 | assert_equal 1, test_node.pages.length | ||
| 20 | assert_nil test_node.draft.user | ||
| 21 | |||
| 22 | 3.times do | ||
| 23 | test_node.find_or_create_draft @user1 | ||
| 24 | end | ||
| 25 | |||
| 26 | assert_equal 1, test_node.pages.length | ||
| 27 | end | ||
| 28 | |||
| 14 | def test_user_gets_assigned_to_unlocked_draft | 29 | def test_user_gets_assigned_to_unlocked_draft |
| 15 | assert_not_nil @first_child.draft | 30 | assert_not_nil @first_child.draft |
| 16 | assert_nil @first_child.draft.user | 31 | assert_nil @first_child.draft.user |
| @@ -34,6 +49,7 @@ class NodeTest < ActiveSupport::TestCase | |||
| 34 | end | 49 | end |
| 35 | 50 | ||
| 36 | def test_publish_draft_on_a_node_without_a_draft_returns_nil | 51 | def test_publish_draft_on_a_node_without_a_draft_returns_nil |
| 52 | |||
| 37 | assert @first_child.publish_draft! | 53 | assert @first_child.publish_draft! |
| 38 | assert_nil @first_child.publish_draft! | 54 | assert_nil @first_child.publish_draft! |
| 39 | end | 55 | end |
| @@ -127,34 +143,34 @@ class NodeTest < ActiveSupport::TestCase | |||
| 127 | 143 | ||
| 128 | def test_order_of_pages_by_revision | 144 | def test_order_of_pages_by_revision |
| 129 | # This test should make sure the order is the same on different db's | 145 | # This test should make sure the order is the same on different db's |
| 130 | 146 | # Remember, there is already an empty draft | |
| 131 | one = @second_child.pages.create :title => "one" | ||
| 132 | two = @second_child.pages.create :title => "two" | 147 | two = @second_child.pages.create :title => "two" |
| 133 | three = @second_child.pages.create :title => "three" | 148 | three = @second_child.pages.create :title => "three" |
| 149 | four = @second_child.pages.create :title => "four" | ||
| 134 | 150 | ||
| 135 | @second_child.pages.reload | 151 | @second_child.pages.reload |
| 136 | 152 | ||
| 137 | assert_equal [1,2,3], @second_child.pages.map { |x| x.revision } | 153 | assert_equal [1,2,3,4], @second_child.pages.map { |x| x.revision } |
| 138 | end | 154 | end |
| 139 | 155 | ||
| 140 | def test_behavior_of_acts_as_list | 156 | def test_behavior_of_acts_as_list |
| 141 | one = @second_child.pages.create :title => "one" | ||
| 142 | two = @second_child.pages.create :title => "two" | 157 | two = @second_child.pages.create :title => "two" |
| 143 | three = @second_child.pages.create :title => "three" | 158 | three = @second_child.pages.create :title => "three" |
| 159 | four = @second_child.pages.create :title => "four" | ||
| 144 | 160 | ||
| 145 | assert_equal 1, one.revision | ||
| 146 | assert_equal 2, two.revision | 161 | assert_equal 2, two.revision |
| 147 | assert_equal 3, three.revision | 162 | assert_equal 3, three.revision |
| 163 | assert_equal 4, four.revision | ||
| 148 | 164 | ||
| 149 | assert_equal three, @second_child.pages.last | 165 | assert_equal four, @second_child.pages.last |
| 150 | 166 | ||
| 151 | assert one.move_to_bottom | 167 | assert two.move_to_bottom |
| 152 | 168 | ||
| 153 | one.reload; two.reload; three.reload; | 169 | two.reload; three.reload; four.reload; |
| 154 | 170 | ||
| 155 | assert_equal 3, one.revision | 171 | assert_equal 4, two.revision |
| 156 | assert_equal 1, two.revision | ||
| 157 | assert_equal 2, three.revision | 172 | assert_equal 2, three.revision |
| 173 | assert_equal 3, four.revision | ||
| 158 | end | 174 | end |
| 159 | 175 | ||
| 160 | def test_retrieving_page_current | 176 | def test_retrieving_page_current |
| @@ -201,4 +217,23 @@ class NodeTest < ActiveSupport::TestCase | |||
| 201 | page = Node.find_page("updates/2008/foo", 2) | 217 | page = Node.find_page("updates/2008/foo", 2) |
| 202 | assert_equal "Version 2", page.title | 218 | assert_equal "Version 2", page.title |
| 203 | end | 219 | end |
| 220 | |||
| 221 | # Thats a lengthy test to make sure everything works as it should, it was | ||
| 222 | # created during a bug hunt | ||
| 223 | def test_creating_new_draft | ||
| 224 | test_node = Node.create! :slug => "test_node" | ||
| 225 | test_node.move_to_child_of Node.root | ||
| 226 | test_node.draft.user = @user1 | ||
| 227 | test_node.save | ||
| 228 | assert test_node.publish_draft! | ||
| 229 | test_node.reload | ||
| 230 | assert_equal 1, test_node.pages.length | ||
| 231 | assert_not_nil test_node.head | ||
| 232 | assert_nil test_node.draft | ||
| 233 | test_node.find_or_create_draft @user1 | ||
| 234 | test_node.reload | ||
| 235 | assert_equal 2, test_node.pages.length | ||
| 236 | assert_not_nil test_node.draft | ||
| 237 | assert test_node.head != test_node.draft | ||
| 238 | end | ||
| 204 | end | 239 | end |
