diff options
Diffstat (limited to 'test/unit/node_test.rb')
| -rw-r--r-- | test/unit/node_test.rb | 59 |
1 files changed, 17 insertions, 42 deletions
diff --git a/test/unit/node_test.rb b/test/unit/node_test.rb index ee4d71f..92870aa 100644 --- a/test/unit/node_test.rb +++ b/test/unit/node_test.rb | |||
| @@ -16,8 +16,7 @@ class NodeTest < ActiveSupport::TestCase | |||
| 16 | end | 16 | end |
| 17 | 17 | ||
| 18 | def test_returning_existing_drafts | 18 | def test_returning_existing_drafts |
| 19 | test_node = Node.create! :slug => "test_node" | 19 | test_node = Node.root.children.create! :slug => "test_node" |
| 20 | test_node.move_to_child_of Node.root | ||
| 21 | 20 | ||
| 22 | assert_not_nil test_node.draft | 21 | assert_not_nil test_node.draft |
| 23 | assert_equal 1, test_node.pages.length | 22 | assert_equal 1, test_node.pages.length |
| @@ -39,10 +38,7 @@ class NodeTest < ActiveSupport::TestCase | |||
| 39 | 38 | ||
| 40 | def test_unique_path_returns_an_array | 39 | def test_unique_path_returns_an_array |
| 41 | assert_equal ["first_child"], @first_child.unique_path | 40 | assert_equal ["first_child"], @first_child.unique_path |
| 42 | 41 | new_node = @first_child.children.create! :slug => "third_child" | |
| 43 | new_node = Node.create! :slug => "third_child" | ||
| 44 | new_node.move_to_child_of @first_child | ||
| 45 | |||
| 46 | assert_equal ["first_child", "third_child"], new_node.unique_path | 42 | assert_equal ["first_child", "third_child"], new_node.unique_path |
| 47 | end | 43 | end |
| 48 | 44 | ||
| @@ -87,8 +83,7 @@ class NodeTest < ActiveSupport::TestCase | |||
| 87 | end | 83 | end |
| 88 | 84 | ||
| 89 | def test_created_nodes_have_an_empty_draft_and_no_head | 85 | def test_created_nodes_have_an_empty_draft_and_no_head |
| 90 | node = Node.create :slug => "third_child" | 86 | node = Node.root.children.create! :slug => "third_child_beta" |
| 91 | node.move_to_child_of @root | ||
| 92 | 87 | ||
| 93 | assert !node.pages.empty? | 88 | assert !node.pages.empty? |
| 94 | assert_equal 1, node.pages.length | 89 | assert_equal 1, node.pages.length |
| @@ -98,23 +93,18 @@ class NodeTest < ActiveSupport::TestCase | |||
| 98 | end | 93 | end |
| 99 | 94 | ||
| 100 | def test_create_new_draft_of_published_page | 95 | def test_create_new_draft_of_published_page |
| 101 | node = Node.create :slug => "xyz" | 96 | node = Node.root.children.create :slug => "xyz" |
| 102 | node.move_to_child_of @root | ||
| 103 | |||
| 104 | assert node.publish_draft! | 97 | assert node.publish_draft! |
| 105 | end | 98 | end |
| 106 | 99 | ||
| 107 | def test_find_or_create_draft_if_no_draft_exists | 100 | def test_find_or_create_draft_if_no_draft_exists |
| 108 | node = Node.create :slug => "xyz" | 101 | node = Node.root.children.create :slug => "xyz" |
| 109 | node.move_to_child_of @root | ||
| 110 | node.publish_draft! | 102 | node.publish_draft! |
| 111 | |||
| 112 | assert_not_nil node.find_or_create_draft( @user1 ) | 103 | assert_not_nil node.find_or_create_draft( @user1 ) |
| 113 | end | 104 | end |
| 114 | 105 | ||
| 115 | def test_find_or_create_draft_if_draft_exists_and_is_owned_by_user | 106 | def test_find_or_create_draft_if_draft_exists_and_is_owned_by_user |
| 116 | node = Node.create :slug => "xyz" | 107 | node = Node.root.children.create :slug => "xyz" |
| 117 | node.move_to_child_of @root | ||
| 118 | node.publish_draft! | 108 | node.publish_draft! |
| 119 | 109 | ||
| 120 | node.find_or_create_draft @user1 | 110 | node.find_or_create_draft @user1 |
| @@ -122,8 +112,7 @@ class NodeTest < ActiveSupport::TestCase | |||
| 122 | end | 112 | end |
| 123 | 113 | ||
| 124 | def test_exception_if_draft_exists_but_locked_by_another_user | 114 | def test_exception_if_draft_exists_but_locked_by_another_user |
| 125 | node = Node.create :slug => "xyz" | 115 | node = Node.root.children.create :slug => "xyz" |
| 126 | node.move_to_child_of @root | ||
| 127 | node.publish_draft! | 116 | node.publish_draft! |
| 128 | node.find_or_create_draft @user1 | 117 | node.find_or_create_draft @user1 |
| 129 | assert_equal @user1, node.lock_owner | 118 | assert_equal @user1, node.lock_owner |
| @@ -133,13 +122,11 @@ class NodeTest < ActiveSupport::TestCase | |||
| 133 | end | 122 | end |
| 134 | 123 | ||
| 135 | def test_creation_of_unique_name | 124 | def test_creation_of_unique_name |
| 136 | node = Node.create :slug => 'child' | 125 | node = Node.root.children.create :slug => 'child' |
| 137 | node.move_to_child_of @root | ||
| 138 | node.reload | 126 | node.reload |
| 139 | assert_equal 'child', node.unique_name | 127 | assert_equal 'child', node.unique_name |
| 140 | 128 | ||
| 141 | node = Node.create :slug => 'deep_child' | 129 | node = @first_child.children.create :slug => 'deep_child' |
| 142 | node.move_to_child_of @first_child | ||
| 143 | node.reload | 130 | node.reload |
| 144 | assert_equal 'first_child/deep_child', node.unique_name | 131 | assert_equal 'first_child/deep_child', node.unique_name |
| 145 | end | 132 | end |
| @@ -177,14 +164,9 @@ class NodeTest < ActiveSupport::TestCase | |||
| 177 | end | 164 | end |
| 178 | 165 | ||
| 179 | def test_retrieving_page_current | 166 | def test_retrieving_page_current |
| 180 | updates = Node.create(:slug => 'updates') | 167 | updates = Node.root.children.create(:slug => 'updates') |
| 181 | updates.move_to_child_of @root | 168 | year = updates.children.create(:slug => '2008') |
| 182 | 169 | foo = year.children.create(:slug => 'foo') | |
| 183 | year = Node.create(:slug => '2008') | ||
| 184 | year.move_to_child_of updates | ||
| 185 | |||
| 186 | foo = Node.create(:slug => 'foo') | ||
| 187 | foo.move_to_child_of year | ||
| 188 | 170 | ||
| 189 | assert_not_nil Node.find_by_unique_name('updates/2008/foo') | 171 | assert_not_nil Node.find_by_unique_name('updates/2008/foo') |
| 190 | 172 | ||
| @@ -201,14 +183,9 @@ class NodeTest < ActiveSupport::TestCase | |||
| 201 | end | 183 | end |
| 202 | 184 | ||
| 203 | def test_retrieving_page_by_revision | 185 | def test_retrieving_page_by_revision |
| 204 | updates = Node.create(:slug => 'updates') | 186 | updates = Node.root.children.create(:slug => 'updates') |
| 205 | updates.move_to_child_of @root | 187 | year = updates.children.create(:slug => '2008') |
| 206 | 188 | foo = year.children.create(:slug => 'foo') | |
| 207 | year = Node.create(:slug => '2008') | ||
| 208 | year.move_to_child_of updates | ||
| 209 | |||
| 210 | foo = Node.create(:slug => 'foo') | ||
| 211 | foo.move_to_child_of year | ||
| 212 | 189 | ||
| 213 | assert_not_nil Node.find_by_unique_name('updates/2008/foo') | 190 | assert_not_nil Node.find_by_unique_name('updates/2008/foo') |
| 214 | 191 | ||
| @@ -224,8 +201,7 @@ class NodeTest < ActiveSupport::TestCase | |||
| 224 | # Thats a lengthy test to make sure everything works as it should, it was | 201 | # Thats a lengthy test to make sure everything works as it should, it was |
| 225 | # created during a bug hunt | 202 | # created during a bug hunt |
| 226 | def test_creating_new_draft | 203 | def test_creating_new_draft |
| 227 | test_node = Node.create! :slug => "test_node" | 204 | test_node = Node.root.children.create! :slug => "test_node" |
| 228 | test_node.move_to_child_of Node.root | ||
| 229 | test_node.draft.user = @user1 | 205 | test_node.draft.user = @user1 |
| 230 | test_node.save | 206 | test_node.save |
| 231 | assert test_node.publish_draft! | 207 | assert test_node.publish_draft! |
| @@ -241,8 +217,7 @@ class NodeTest < ActiveSupport::TestCase | |||
| 241 | end | 217 | end |
| 242 | 218 | ||
| 243 | test "restoring a revision" do | 219 | test "restoring a revision" do |
| 244 | test_node = Node.create! :slug => "test_node" | 220 | test_node = Node.root.children.create! :slug => "test_node" |
| 245 | test_node.move_to_child_of Node.root | ||
| 246 | create_revisions( test_node, 3 ) | 221 | create_revisions( test_node, 3 ) |
| 247 | test_node.find_or_create_draft @user1 | 222 | test_node.find_or_create_draft @user1 |
| 248 | test_node.reload | 223 | test_node.reload |
