annotate test/unit/wiki_content_test.rb @ 1296:038ba2d95de8 redmine-2.2

Fix redmine-2.2 branch update (add missing svn files)
author Chris Cannam
date Fri, 14 Jun 2013 09:05:06 +0100
parents 433d4f72a19b
children 622f24f53b42 261b3d9a4903
rev   line source
Chris@441 1 # Redmine - project management software
Chris@1115 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
Chris@0 3 #
Chris@0 4 # This program is free software; you can redistribute it and/or
Chris@0 5 # modify it under the terms of the GNU General Public License
Chris@0 6 # as published by the Free Software Foundation; either version 2
Chris@0 7 # of the License, or (at your option) any later version.
Chris@441 8 #
Chris@0 9 # This program is distributed in the hope that it will be useful,
Chris@0 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 12 # GNU General Public License for more details.
Chris@441 13 #
Chris@0 14 # You should have received a copy of the GNU General Public License
Chris@0 15 # along with this program; if not, write to the Free Software
Chris@0 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@0 17
Chris@119 18 require File.expand_path('../../test_helper', __FILE__)
Chris@0 19
Chris@0 20 class WikiContentTest < ActiveSupport::TestCase
Chris@1115 21 fixtures :projects, :enabled_modules,
Chris@1115 22 :users, :members, :member_roles, :roles,
Chris@1115 23 :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions
Chris@0 24
Chris@0 25 def setup
Chris@0 26 @wiki = Wiki.find(1)
Chris@0 27 @page = @wiki.pages.first
Chris@0 28 end
Chris@441 29
Chris@0 30 def test_create
Chris@441 31 page = WikiPage.new(:wiki => @wiki, :title => "Page")
Chris@0 32 page.content = WikiContent.new(:text => "Content text", :author => User.find(1), :comments => "My comment")
Chris@0 33 assert page.save
Chris@0 34 page.reload
Chris@441 35
Chris@0 36 content = page.content
Chris@0 37 assert_kind_of WikiContent, content
Chris@0 38 assert_equal 1, content.version
Chris@0 39 assert_equal 1, content.versions.length
Chris@0 40 assert_equal "Content text", content.text
Chris@0 41 assert_equal "My comment", content.comments
Chris@0 42 assert_equal User.find(1), content.author
Chris@0 43 assert_equal content.text, content.versions.last.text
Chris@0 44 end
Chris@441 45
Chris@0 46 def test_create_should_send_email_notification
Chris@0 47 ActionMailer::Base.deliveries.clear
Chris@441 48 page = WikiPage.new(:wiki => @wiki, :title => "A new page")
Chris@0 49 page.content = WikiContent.new(:text => "Content text", :author => User.find(1), :comments => "My comment")
Chris@1115 50
Chris@1115 51 with_settings :notified_events => %w(wiki_content_added) do
Chris@1115 52 assert page.save
Chris@1115 53 end
Chris@441 54
Chris@0 55 assert_equal 1, ActionMailer::Base.deliveries.size
Chris@0 56 end
Chris@0 57
Chris@1115 58 def test_update_should_be_versioned
Chris@0 59 content = @page.content
Chris@0 60 version_count = content.version
Chris@0 61 content.text = "My new content"
Chris@1115 62 assert_difference 'WikiContent::Version.count' do
Chris@1115 63 assert content.save
Chris@1115 64 end
Chris@0 65 content.reload
Chris@0 66 assert_equal version_count+1, content.version
Chris@0 67 assert_equal version_count+1, content.versions.length
Chris@1115 68
Chris@1115 69 version = WikiContent::Version.first(:order => 'id DESC')
Chris@1115 70 assert_equal @page.id, version.page_id
Chris@1115 71 assert_equal '', version.compression
Chris@1115 72 assert_equal "My new content", version.data
Chris@1115 73 assert_equal "My new content", version.text
Chris@1115 74 end
Chris@1115 75
Chris@1115 76 def test_update_with_gzipped_history
Chris@1115 77 with_settings :wiki_compression => 'gzip' do
Chris@1115 78 content = @page.content
Chris@1115 79 content.text = "My new content"
Chris@1115 80 assert_difference 'WikiContent::Version.count' do
Chris@1115 81 assert content.save
Chris@1115 82 end
Chris@1115 83 end
Chris@1115 84
Chris@1115 85 version = WikiContent::Version.first(:order => 'id DESC')
Chris@1115 86 assert_equal @page.id, version.page_id
Chris@1115 87 assert_equal 'gzip', version.compression
Chris@1115 88 assert_not_equal "My new content", version.data
Chris@1115 89 assert_equal "My new content", version.text
Chris@0 90 end
Chris@441 91
Chris@0 92 def test_update_should_send_email_notification
Chris@0 93 ActionMailer::Base.deliveries.clear
Chris@0 94 content = @page.content
Chris@0 95 content.text = "My new content"
Chris@1115 96
Chris@1115 97 with_settings :notified_events => %w(wiki_content_updated) do
Chris@1115 98 assert content.save
Chris@1115 99 end
Chris@441 100
Chris@0 101 assert_equal 1, ActionMailer::Base.deliveries.size
Chris@0 102 end
Chris@441 103
Chris@0 104 def test_fetch_history
Chris@0 105 assert !@page.content.versions.empty?
Chris@0 106 @page.content.versions.each do |version|
Chris@0 107 assert_kind_of String, version.text
Chris@0 108 end
Chris@0 109 end
Chris@441 110
Chris@0 111 def test_large_text_should_not_be_truncated_to_64k
Chris@441 112 page = WikiPage.new(:wiki => @wiki, :title => "Big page")
Chris@0 113 page.content = WikiContent.new(:text => "a" * 500.kilobyte, :author => User.find(1))
Chris@0 114 assert page.save
Chris@0 115 page.reload
Chris@0 116 assert_equal 500.kilobyte, page.content.text.size
Chris@0 117 end
Chris@909 118
Chris@909 119 def test_current_version
Chris@909 120 content = WikiContent.find(11)
Chris@909 121 assert_equal true, content.current_version?
Chris@909 122 assert_equal true, content.versions.first(:order => 'version DESC').current_version?
Chris@909 123 assert_equal false, content.versions.first(:order => 'version ASC').current_version?
Chris@909 124 end
Chris@1115 125
Chris@1115 126 def test_previous_for_first_version_should_return_nil
Chris@1115 127 content = WikiContent::Version.find_by_page_id_and_version(1, 1)
Chris@1115 128 assert_nil content.previous
Chris@1115 129 end
Chris@1115 130
Chris@1115 131 def test_previous_for_version_should_return_previous_version
Chris@1115 132 content = WikiContent::Version.find_by_page_id_and_version(1, 3)
Chris@1115 133 assert_not_nil content.previous
Chris@1115 134 assert_equal 2, content.previous.version
Chris@1115 135 end
Chris@1115 136
Chris@1115 137 def test_previous_for_version_with_gap_should_return_previous_available_version
Chris@1115 138 WikiContent::Version.find_by_page_id_and_version(1, 2).destroy
Chris@1115 139
Chris@1115 140 content = WikiContent::Version.find_by_page_id_and_version(1, 3)
Chris@1115 141 assert_not_nil content.previous
Chris@1115 142 assert_equal 1, content.previous.version
Chris@1115 143 end
Chris@1115 144
Chris@1115 145 def test_next_for_last_version_should_return_nil
Chris@1115 146 content = WikiContent::Version.find_by_page_id_and_version(1, 3)
Chris@1115 147 assert_nil content.next
Chris@1115 148 end
Chris@1115 149
Chris@1115 150 def test_next_for_version_should_return_next_version
Chris@1115 151 content = WikiContent::Version.find_by_page_id_and_version(1, 1)
Chris@1115 152 assert_not_nil content.next
Chris@1115 153 assert_equal 2, content.next.version
Chris@1115 154 end
Chris@1115 155
Chris@1115 156 def test_next_for_version_with_gap_should_return_next_available_version
Chris@1115 157 WikiContent::Version.find_by_page_id_and_version(1, 2).destroy
Chris@1115 158
Chris@1115 159 content = WikiContent::Version.find_by_page_id_and_version(1, 1)
Chris@1115 160 assert_not_nil content.next
Chris@1115 161 assert_equal 3, content.next.version
Chris@1115 162 end
Chris@0 163 end