Handle deleted wiki page versions (#10852).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10684 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang
2012-10-21 04:43:15 +00:00
parent f09be68323
commit 9796d18609
5 changed files with 68 additions and 11 deletions
+38
View File
@@ -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
+10
View File
@@ -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