summaryrefslogtreecommitdiffstats
path: root/test/unit
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2012-10-21 04:43:15 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2012-10-21 04:43:15 +0000
commit9796d18609334eaad05188617217f2405a47a645 (patch)
tree738c1a31646f87f541e2403455611895b917a2d5 /test/unit
parentf09be683232748ba649de6b3c1b62f901d9247b8 (diff)
downloadredmine-9796d18609334eaad05188617217f2405a47a645.tar.gz
redmine-9796d18609334eaad05188617217f2405a47a645.zip
Handle deleted wiki page versions (#10852).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10684 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/wiki_content_test.rb38
-rw-r--r--test/unit/wiki_page_test.rb10
2 files changed, 48 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
diff --git a/test/unit/wiki_page_test.rb b/test/unit/wiki_page_test.rb
index 2a606a782..8eb2af0ea 100644
--- a/test/unit/wiki_page_test.rb
+++ b/test/unit/wiki_page_test.rb
@@ -149,4 +149,14 @@ class WikiPageTest < ActiveSupport::TestCase
assert_equal %w(Child1 Child11 Child2 Parent), page.self_and_descendants(2).map(&:title).sort
assert_equal %w(Child1 Child2 Parent), page.self_and_descendants(1).map(&:title).sort
end
+
+ def test_diff_for_page_with_deleted_version_should_pick_the_previous_available_version
+ WikiContent::Version.find_by_page_id_and_version(1, 2).destroy
+
+ page = WikiPage.find(1)
+ diff = page.diff(3)
+ assert_not_nil diff
+ assert_equal 3, diff.content_to.version
+ assert_equal 1, diff.content_from.version
+ end
end