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 | |
| 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')
| -rw-r--r-- | test/fixtures/nodes.yml | 3 | ||||
| -rw-r--r-- | test/fixtures/pages.yml | 15 | ||||
| -rw-r--r-- | test/functional/nodes_controller_test.rb | 19 | ||||
| -rw-r--r-- | test/unit/node_test.rb | 55 |
4 files changed, 79 insertions, 13 deletions
diff --git a/test/fixtures/nodes.yml b/test/fixtures/nodes.yml index 642d937..8574c1b 100644 --- a/test/fixtures/nodes.yml +++ b/test/fixtures/nodes.yml | |||
| @@ -14,6 +14,7 @@ first_child: | |||
| 14 | lft: 2 | 14 | lft: 2 |
| 15 | rgt: 3 | 15 | rgt: 3 |
| 16 | parent_id: 1 | 16 | parent_id: 1 |
| 17 | draft_id: 100 | ||
| 17 | slug: first_child | 18 | slug: first_child |
| 18 | unique_name: first_child | 19 | unique_name: first_child |
| 19 | 20 | ||
| @@ -22,6 +23,7 @@ second_child: | |||
| 22 | lft: 4 | 23 | lft: 4 |
| 23 | rgt: 5 | 24 | rgt: 5 |
| 24 | parent_id: 1 | 25 | parent_id: 1 |
| 26 | draft_id: 101 | ||
| 25 | slug: second_child | 27 | slug: second_child |
| 26 | unique_name: second_child | 28 | unique_name: second_child |
| 27 | 29 | ||
| @@ -30,5 +32,6 @@ third_child: | |||
| 30 | lft: 6 | 32 | lft: 6 |
| 31 | rgt: 7 | 33 | rgt: 7 |
| 32 | parent_id: 1 | 34 | parent_id: 1 |
| 35 | draft_id: 102 | ||
| 33 | slug: third_child | 36 | slug: third_child |
| 34 | unique_name: third_child \ No newline at end of file | 37 | unique_name: third_child \ No newline at end of file |
diff --git a/test/fixtures/pages.yml b/test/fixtures/pages.yml index 614b9a6..8171b38 100644 --- a/test/fixtures/pages.yml +++ b/test/fixtures/pages.yml | |||
| @@ -8,4 +8,19 @@ one: | |||
| 8 | two: | 8 | two: |
| 9 | id: 2 | 9 | id: 2 |
| 10 | revision: 1 | 10 | revision: 1 |
| 11 | node_id: 4 | ||
| 12 | |||
| 13 | draft1: | ||
| 14 | id: 100 | ||
| 15 | revision: 1 | ||
| 16 | node_id: 2 | ||
| 17 | |||
| 18 | draft2: | ||
| 19 | id: 101 | ||
| 20 | revision: 1 | ||
| 21 | node_id: 3 | ||
| 22 | |||
| 23 | draft3: | ||
| 24 | id: 102 | ||
| 25 | revision: 1 | ||
| 11 | node_id: 4 \ No newline at end of file | 26 | node_id: 4 \ No newline at end of file |
diff --git a/test/functional/nodes_controller_test.rb b/test/functional/nodes_controller_test.rb index d6d579d..85f151a 100644 --- a/test/functional/nodes_controller_test.rb +++ b/test/functional/nodes_controller_test.rb | |||
| @@ -1,8 +1,21 @@ | |||
| 1 | require 'test_helper' | 1 | require 'test_helper' |
| 2 | 2 | ||
| 3 | class NodesControllerTest < ActionController::TestCase | 3 | class NodesControllerTest < ActionController::TestCase |
| 4 | # Replace this with your real tests. | 4 | |
| 5 | test "the truth" do | 5 | include AuthenticatedTestHelper |
| 6 | assert true | 6 | |
| 7 | def test_get_index | ||
| 8 | login_as :quentin | ||
| 9 | get :index | ||
| 10 | assert_response :success | ||
| 11 | end | ||
| 12 | |||
| 13 | def test_update_a_draft | ||
| 14 | test_node = Node.create! :slug => "test_node" | ||
| 15 | test_node.move_to_child_of Node.root | ||
| 16 | |||
| 17 | login_as :quentin | ||
| 18 | |||
| 19 | |||
| 7 | end | 20 | end |
| 8 | end | 21 | end |
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 |
