annotate .svn/pristine/5b/5b2317c90ed81995ffba20202367b84382beccbf.svn-base @ 1519:afce8026aaeb redmine-2.4-integration

Merge from branch "live"
author Chris Cannam
date Tue, 09 Sep 2014 09:34:53 +0100
parents cbb26bc654de
children
rev   line source
Chris@909 1 # Redmine - project management software
Chris@909 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
Chris@909 3 #
Chris@909 4 # This program is free software; you can redistribute it and/or
Chris@909 5 # modify it under the terms of the GNU General Public License
Chris@909 6 # as published by the Free Software Foundation; either version 2
Chris@909 7 # of the License, or (at your option) any later version.
Chris@909 8 #
Chris@909 9 # This program is distributed in the hope that it will be useful,
Chris@909 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@909 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@909 12 # GNU General Public License for more details.
Chris@909 13 #
Chris@909 14 # You should have received a copy of the GNU General Public License
Chris@909 15 # along with this program; if not, write to the Free Software
Chris@909 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@909 17
Chris@909 18 require File.expand_path('../../test_helper', __FILE__)
Chris@909 19
Chris@909 20 class WikiContentTest < ActiveSupport::TestCase
Chris@909 21 fixtures :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions, :users
Chris@909 22
Chris@909 23 def setup
Chris@909 24 @wiki = Wiki.find(1)
Chris@909 25 @page = @wiki.pages.first
Chris@909 26 end
Chris@909 27
Chris@909 28 def test_create
Chris@909 29 page = WikiPage.new(:wiki => @wiki, :title => "Page")
Chris@909 30 page.content = WikiContent.new(:text => "Content text", :author => User.find(1), :comments => "My comment")
Chris@909 31 assert page.save
Chris@909 32 page.reload
Chris@909 33
Chris@909 34 content = page.content
Chris@909 35 assert_kind_of WikiContent, content
Chris@909 36 assert_equal 1, content.version
Chris@909 37 assert_equal 1, content.versions.length
Chris@909 38 assert_equal "Content text", content.text
Chris@909 39 assert_equal "My comment", content.comments
Chris@909 40 assert_equal User.find(1), content.author
Chris@909 41 assert_equal content.text, content.versions.last.text
Chris@909 42 end
Chris@909 43
Chris@909 44 def test_create_should_send_email_notification
Chris@909 45 Setting.notified_events = ['wiki_content_added']
Chris@909 46 ActionMailer::Base.deliveries.clear
Chris@909 47 page = WikiPage.new(:wiki => @wiki, :title => "A new page")
Chris@909 48 page.content = WikiContent.new(:text => "Content text", :author => User.find(1), :comments => "My comment")
Chris@909 49 assert page.save
Chris@909 50
Chris@909 51 assert_equal 1, ActionMailer::Base.deliveries.size
Chris@909 52 end
Chris@909 53
Chris@909 54 def test_update
Chris@909 55 content = @page.content
Chris@909 56 version_count = content.version
Chris@909 57 content.text = "My new content"
Chris@909 58 assert content.save
Chris@909 59 content.reload
Chris@909 60 assert_equal version_count+1, content.version
Chris@909 61 assert_equal version_count+1, content.versions.length
Chris@909 62 end
Chris@909 63
Chris@909 64 def test_update_should_send_email_notification
Chris@909 65 Setting.notified_events = ['wiki_content_updated']
Chris@909 66 ActionMailer::Base.deliveries.clear
Chris@909 67 content = @page.content
Chris@909 68 content.text = "My new content"
Chris@909 69 assert content.save
Chris@909 70
Chris@909 71 assert_equal 1, ActionMailer::Base.deliveries.size
Chris@909 72 end
Chris@909 73
Chris@909 74 def test_fetch_history
Chris@909 75 assert !@page.content.versions.empty?
Chris@909 76 @page.content.versions.each do |version|
Chris@909 77 assert_kind_of String, version.text
Chris@909 78 end
Chris@909 79 end
Chris@909 80
Chris@909 81 def test_large_text_should_not_be_truncated_to_64k
Chris@909 82 page = WikiPage.new(:wiki => @wiki, :title => "Big page")
Chris@909 83 page.content = WikiContent.new(:text => "a" * 500.kilobyte, :author => User.find(1))
Chris@909 84 assert page.save
Chris@909 85 page.reload
Chris@909 86 assert_equal 500.kilobyte, page.content.text.size
Chris@909 87 end
Chris@909 88
Chris@909 89 def test_current_version
Chris@909 90 content = WikiContent.find(11)
Chris@909 91 assert_equal true, content.current_version?
Chris@909 92 assert_equal true, content.versions.first(:order => 'version DESC').current_version?
Chris@909 93 assert_equal false, content.versions.first(:order => 'version ASC').current_version?
Chris@909 94 end
Chris@909 95 end