diff options
| author | hukl <hukl@eight.local> | 2009-02-08 15:16:22 +0100 |
|---|---|---|
| committer | hukl <hukl@eight.local> | 2009-02-08 15:16:22 +0100 |
| commit | 56306be42c3cb6bfd0501d69e0f3a1842c8f5989 (patch) | |
| tree | 2e3a13c93a78bb90508608b45b75e7ada5801495 /test/unit/node_test.rb | |
| parent | a6eea1a843c29112a737e77d6cb813c8980fb836 (diff) | |
lots of concept refinements
Diffstat (limited to 'test/unit/node_test.rb')
| -rw-r--r-- | test/unit/node_test.rb | 78 |
1 files changed, 76 insertions, 2 deletions
diff --git a/test/unit/node_test.rb b/test/unit/node_test.rb index 6e62447..d4317ca 100644 --- a/test/unit/node_test.rb +++ b/test/unit/node_test.rb | |||
| @@ -6,6 +6,9 @@ class NodeTest < ActiveSupport::TestCase | |||
| 6 | @root = Node.find(1) | 6 | @root = Node.find(1) |
| 7 | @first_child = Node.find(2) | 7 | @first_child = Node.find(2) |
| 8 | @second_child = Node.find(3) | 8 | @second_child = Node.find(3) |
| 9 | |||
| 10 | @user1 = User.create :login => 'demo' | ||
| 11 | @user2 = User.create :login => 'show' | ||
| 9 | end | 12 | end |
| 10 | 13 | ||
| 11 | def test_created_nodes_have_an_empty_draft_and_no_head | 14 | def test_created_nodes_have_an_empty_draft_and_no_head |
| @@ -15,6 +18,7 @@ class NodeTest < ActiveSupport::TestCase | |||
| 15 | assert !node.pages.empty? | 18 | assert !node.pages.empty? |
| 16 | assert_equal 1, node.pages.length | 19 | assert_equal 1, node.pages.length |
| 17 | assert_not_nil node.draft | 20 | assert_not_nil node.draft |
| 21 | assert_nil node.draft.user | ||
| 18 | assert_nil node.head | 22 | assert_nil node.head |
| 19 | end | 23 | end |
| 20 | 24 | ||
| @@ -23,10 +27,35 @@ class NodeTest < ActiveSupport::TestCase | |||
| 23 | node.move_to_child_of @root | 27 | node.move_to_child_of @root |
| 24 | 28 | ||
| 25 | assert node.publish_draft! | 29 | assert node.publish_draft! |
| 30 | end | ||
| 31 | |||
| 32 | def test_find_or_create_draft_if_no_draft_exists | ||
| 33 | node = Node.create :slug => "third_child" | ||
| 34 | node.move_to_child_of @root | ||
| 35 | node.publish_draft! | ||
| 36 | |||
| 37 | assert_not_nil node.find_or_create_draft( @user1 ) | ||
| 38 | end | ||
| 39 | |||
| 40 | def test_find_or_create_draft_if_draft_exists_and_is_owned_by_user | ||
| 41 | node = Node.create :slug => "third_child" | ||
| 42 | node.move_to_child_of @root | ||
| 43 | node.publish_draft! | ||
| 44 | |||
| 45 | node.find_or_create_draft @user1 | ||
| 46 | node.find_or_create_draft @user1 | ||
| 47 | end | ||
| 48 | |||
| 49 | def test_exception_if_draft_exists_but_locked_by_another_user | ||
| 50 | node = Node.create :slug => "third_child" | ||
| 51 | node.move_to_child_of @root | ||
| 52 | node.publish_draft! | ||
| 26 | 53 | ||
| 27 | draft = node.draft | 54 | node.find_or_create_draft @user1 |
| 28 | 55 | ||
| 29 | assert_equal 2, node.pages.length | 56 | assert_raise(RuntimeError) do |
| 57 | node.find_or_create_draft @user2 | ||
| 58 | end | ||
| 30 | end | 59 | end |
| 31 | 60 | ||
| 32 | def test_creation_of_unique_name | 61 | def test_creation_of_unique_name |
| @@ -72,4 +101,49 @@ class NodeTest < ActiveSupport::TestCase | |||
| 72 | assert_equal 1, two.revision | 101 | assert_equal 1, two.revision |
| 73 | assert_equal 2, three.revision | 102 | assert_equal 2, three.revision |
| 74 | end | 103 | end |
| 104 | |||
| 105 | def test_retrieving_page_current | ||
| 106 | updates = Node.create(:slug => 'updates') | ||
| 107 | updates.move_to_child_of @root | ||
| 108 | |||
| 109 | year = Node.create(:slug => '2008') | ||
| 110 | year.move_to_child_of updates | ||
| 111 | |||
| 112 | foo = Node.create(:slug => 'foo') | ||
| 113 | foo.move_to_child_of year | ||
| 114 | |||
| 115 | assert_not_nil Node.find_by_unique_name('updates/2008/foo') | ||
| 116 | |||
| 117 | # Note that there is already an initial, blank revision | ||
| 118 | foo.pages.create :title => "Version 2" | ||
| 119 | foo.pages.create :title => "Version 3" | ||
| 120 | foo.pages.create :title => "Version 4" | ||
| 121 | |||
| 122 | foo.head = foo.pages.last | ||
| 123 | foo.save! | ||
| 124 | |||
| 125 | page = Node.find_page("updates/2008/foo") | ||
| 126 | assert_equal page, foo.pages.find_by_revision(4) | ||
| 127 | end | ||
| 128 | |||
| 129 | def test_retrieving_page_by_revision | ||
| 130 | updates = Node.create(:slug => 'updates') | ||
| 131 | updates.move_to_child_of @root | ||
| 132 | |||
| 133 | year = Node.create(:slug => '2008') | ||
| 134 | year.move_to_child_of updates | ||
| 135 | |||
| 136 | foo = Node.create(:slug => 'foo') | ||
| 137 | foo.move_to_child_of year | ||
| 138 | |||
| 139 | assert_not_nil Node.find_by_unique_name('updates/2008/foo') | ||
| 140 | |||
| 141 | # Note that there is already an initial, blank revision | ||
| 142 | foo.pages.create :title => "Version 2" | ||
| 143 | foo.pages.create :title => "Version 3" | ||
| 144 | foo.pages.create :title => "Version 4" | ||
| 145 | |||
| 146 | page = Node.find_page("updates/2008/foo", 2) | ||
| 147 | assert_equal "Version 2", page.title | ||
| 148 | end | ||
| 75 | end | 149 | end |
