diff test/unit/wiki_content_test.rb @ 1115:433d4f72a19b redmine-2.2

Update to Redmine SVN revision 11137 on 2.2-stable branch
author Chris Cannam
date Mon, 07 Jan 2013 12:01:42 +0000
parents cbb26bc654de
children 622f24f53b42 261b3d9a4903
line wrap: on
line diff
--- a/test/unit/wiki_content_test.rb	Wed Jun 27 14:54:18 2012 +0100
+++ b/test/unit/wiki_content_test.rb	Mon Jan 07 12:01:42 2013 +0000
@@ -1,5 +1,5 @@
 # Redmine - project management software
-# Copyright (C) 2006-2011  Jean-Philippe Lang
+# Copyright (C) 2006-2012  Jean-Philippe Lang
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
@@ -18,7 +18,9 @@
 require File.expand_path('../../test_helper', __FILE__)
 
 class WikiContentTest < ActiveSupport::TestCase
-  fixtures :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions, :users
+  fixtures :projects, :enabled_modules,
+           :users, :members, :member_roles, :roles,
+           :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions
 
   def setup
     @wiki = Wiki.find(1)
@@ -42,31 +44,59 @@
   end
 
   def test_create_should_send_email_notification
-    Setting.notified_events = ['wiki_content_added']
     ActionMailer::Base.deliveries.clear
     page = WikiPage.new(:wiki => @wiki, :title => "A new page")
     page.content = WikiContent.new(:text => "Content text", :author => User.find(1), :comments => "My comment")
-    assert page.save
+
+    with_settings :notified_events => %w(wiki_content_added) do
+      assert page.save
+    end
 
     assert_equal 1, ActionMailer::Base.deliveries.size
   end
 
-  def test_update
+  def test_update_should_be_versioned
     content = @page.content
     version_count = content.version
     content.text = "My new content"
-    assert content.save
+    assert_difference 'WikiContent::Version.count' do
+      assert content.save
+    end
     content.reload
     assert_equal version_count+1, content.version
     assert_equal version_count+1, content.versions.length
+
+    version = WikiContent::Version.first(:order => 'id DESC')
+    assert_equal @page.id, version.page_id
+    assert_equal '', version.compression
+    assert_equal "My new content", version.data
+    assert_equal "My new content", version.text
+  end
+
+  def test_update_with_gzipped_history
+    with_settings :wiki_compression => 'gzip' do
+      content = @page.content
+      content.text = "My new content"
+      assert_difference 'WikiContent::Version.count' do
+        assert content.save
+      end
+    end
+
+    version = WikiContent::Version.first(:order => 'id DESC')
+    assert_equal @page.id, version.page_id
+    assert_equal 'gzip', version.compression
+    assert_not_equal "My new content", version.data
+    assert_equal "My new content", version.text
   end
 
   def test_update_should_send_email_notification
-    Setting.notified_events = ['wiki_content_updated']
     ActionMailer::Base.deliveries.clear
     content = @page.content
     content.text = "My new content"
-    assert content.save
+
+    with_settings :notified_events => %w(wiki_content_updated) do
+      assert content.save
+    end
 
     assert_equal 1, ActionMailer::Base.deliveries.size
   end
@@ -92,4 +122,42 @@
     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