From 56306be42c3cb6bfd0501d69e0f3a1842c8f5989 Mon Sep 17 00:00:00 2001 From: hukl Date: Sun, 8 Feb 2009 15:16:22 +0100 Subject: lots of concept refinements --- test/unit/node_test.rb | 78 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 76 insertions(+), 2 deletions(-) (limited to 'test/unit/node_test.rb') 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 @root = Node.find(1) @first_child = Node.find(2) @second_child = Node.find(3) + + @user1 = User.create :login => 'demo' + @user2 = User.create :login => 'show' end def test_created_nodes_have_an_empty_draft_and_no_head @@ -15,6 +18,7 @@ class NodeTest < ActiveSupport::TestCase assert !node.pages.empty? assert_equal 1, node.pages.length assert_not_nil node.draft + assert_nil node.draft.user assert_nil node.head end @@ -23,10 +27,35 @@ class NodeTest < ActiveSupport::TestCase node.move_to_child_of @root assert node.publish_draft! + end + + def test_find_or_create_draft_if_no_draft_exists + node = Node.create :slug => "third_child" + node.move_to_child_of @root + node.publish_draft! + + assert_not_nil node.find_or_create_draft( @user1 ) + end + + def test_find_or_create_draft_if_draft_exists_and_is_owned_by_user + node = Node.create :slug => "third_child" + node.move_to_child_of @root + node.publish_draft! + + node.find_or_create_draft @user1 + node.find_or_create_draft @user1 + end + + def test_exception_if_draft_exists_but_locked_by_another_user + node = Node.create :slug => "third_child" + node.move_to_child_of @root + node.publish_draft! - draft = node.draft + node.find_or_create_draft @user1 - assert_equal 2, node.pages.length + assert_raise(RuntimeError) do + node.find_or_create_draft @user2 + end end def test_creation_of_unique_name @@ -72,4 +101,49 @@ class NodeTest < ActiveSupport::TestCase assert_equal 1, two.revision assert_equal 2, three.revision end + + def test_retrieving_page_current + updates = Node.create(:slug => 'updates') + updates.move_to_child_of @root + + year = Node.create(:slug => '2008') + year.move_to_child_of updates + + foo = Node.create(:slug => 'foo') + foo.move_to_child_of year + + assert_not_nil Node.find_by_unique_name('updates/2008/foo') + + # Note that there is already an initial, blank revision + foo.pages.create :title => "Version 2" + foo.pages.create :title => "Version 3" + foo.pages.create :title => "Version 4" + + foo.head = foo.pages.last + foo.save! + + page = Node.find_page("updates/2008/foo") + assert_equal page, foo.pages.find_by_revision(4) + end + + def test_retrieving_page_by_revision + updates = Node.create(:slug => 'updates') + updates.move_to_child_of @root + + year = Node.create(:slug => '2008') + year.move_to_child_of updates + + foo = Node.create(:slug => 'foo') + foo.move_to_child_of year + + assert_not_nil Node.find_by_unique_name('updates/2008/foo') + + # Note that there is already an initial, blank revision + foo.pages.create :title => "Version 2" + foo.pages.create :title => "Version 3" + foo.pages.create :title => "Version 4" + + page = Node.find_page("updates/2008/foo", 2) + assert_equal "Version 2", page.title + end end -- cgit v1.3