diff options
Diffstat (limited to 'test/unit/wiki_content_test.rb')
-rw-r--r-- | test/unit/wiki_content_test.rb | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/test/unit/wiki_content_test.rb b/test/unit/wiki_content_test.rb index 420095807..b49aba008 100644 --- a/test/unit/wiki_content_test.rb +++ b/test/unit/wiki_content_test.rb @@ -122,4 +122,42 @@ class WikiContentTest < ActiveSupport::TestCase assert_equal true, content.versions.first(:order => 'version DESC').current_version? assert_equal false, content.versions.first(:order => 'version ASC').current_version? end + + def test_previous_for_first_version_should_return_nil + content = WikiContent::Version.find_by_page_id_and_version(1, 1) + assert_nil content.previous + end + + def test_previous_for_version_should_return_previous_version + content = WikiContent::Version.find_by_page_id_and_version(1, 3) + assert_not_nil content.previous + assert_equal 2, content.previous.version + end + + def test_previous_for_version_with_gap_should_return_previous_available_version + WikiContent::Version.find_by_page_id_and_version(1, 2).destroy + + content = WikiContent::Version.find_by_page_id_and_version(1, 3) + assert_not_nil content.previous + assert_equal 1, content.previous.version + end + + def test_next_for_last_version_should_return_nil + content = WikiContent::Version.find_by_page_id_and_version(1, 3) + assert_nil content.next + end + + def test_next_for_version_should_return_next_version + content = WikiContent::Version.find_by_page_id_and_version(1, 1) + assert_not_nil content.next + assert_equal 2, content.next.version + end + + def test_next_for_version_with_gap_should_return_next_available_version + WikiContent::Version.find_by_page_id_and_version(1, 2).destroy + + content = WikiContent::Version.find_by_page_id_and_version(1, 1) + assert_not_nil content.next + assert_equal 3, content.next.version + end end |