From 9796d18609334eaad05188617217f2405a47a645 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sun, 21 Oct 2012 04:43:15 +0000 Subject: Handle deleted wiki page versions (#10852). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10684 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- test/unit/wiki_content_test.rb | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'test/unit/wiki_content_test.rb') 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 -- cgit v1.2.3