##// END OF EJS Templates
Additional test for gzipped wiki history....
Jean-Philippe Lang -
r9232:cfb06a2607e3
parent child
Show More
@@ -1,97 +1,121
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19
20 20 class WikiContentTest < ActiveSupport::TestCase
21 21 fixtures :projects, :enabled_modules,
22 22 :users, :members, :member_roles, :roles,
23 23 :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions
24 24
25 25 def setup
26 26 @wiki = Wiki.find(1)
27 27 @page = @wiki.pages.first
28 28 end
29 29
30 30 def test_create
31 31 page = WikiPage.new(:wiki => @wiki, :title => "Page")
32 32 page.content = WikiContent.new(:text => "Content text", :author => User.find(1), :comments => "My comment")
33 33 assert page.save
34 34 page.reload
35 35
36 36 content = page.content
37 37 assert_kind_of WikiContent, content
38 38 assert_equal 1, content.version
39 39 assert_equal 1, content.versions.length
40 40 assert_equal "Content text", content.text
41 41 assert_equal "My comment", content.comments
42 42 assert_equal User.find(1), content.author
43 43 assert_equal content.text, content.versions.last.text
44 44 end
45 45
46 46 def test_create_should_send_email_notification
47 47 Setting.notified_events = ['wiki_content_added']
48 48 ActionMailer::Base.deliveries.clear
49 49 page = WikiPage.new(:wiki => @wiki, :title => "A new page")
50 50 page.content = WikiContent.new(:text => "Content text", :author => User.find(1), :comments => "My comment")
51 51 assert page.save
52 52
53 53 assert_equal 1, ActionMailer::Base.deliveries.size
54 54 end
55 55
56 def test_update
56 def test_update_should_be_versioned
57 57 content = @page.content
58 58 version_count = content.version
59 59 content.text = "My new content"
60 assert_difference 'WikiContent::Version.count' do
60 61 assert content.save
62 end
61 63 content.reload
62 64 assert_equal version_count+1, content.version
63 65 assert_equal version_count+1, content.versions.length
66
67 version = WikiContent::Version.first(:order => 'id DESC')
68 assert_equal @page.id, version.page_id
69 assert_equal '', version.compression
70 assert_equal "My new content", version.data
71 assert_equal "My new content", version.text
72 end
73
74 def test_update_with_gzipped_history
75 with_settings :wiki_compression => 'gzip' do
76 content = @page.content
77 content.text = "My new content"
78 assert_difference 'WikiContent::Version.count' do
79 assert content.save
80 end
81 end
82
83 version = WikiContent::Version.first(:order => 'id DESC')
84 assert_equal @page.id, version.page_id
85 assert_equal 'gzip', version.compression
86 assert_not_equal "My new content", version.data
87 assert_equal "My new content", version.text
64 88 end
65 89
66 90 def test_update_should_send_email_notification
67 91 Setting.notified_events = ['wiki_content_updated']
68 92 ActionMailer::Base.deliveries.clear
69 93 content = @page.content
70 94 content.text = "My new content"
71 95 assert content.save
72 96
73 97 assert_equal 1, ActionMailer::Base.deliveries.size
74 98 end
75 99
76 100 def test_fetch_history
77 101 assert !@page.content.versions.empty?
78 102 @page.content.versions.each do |version|
79 103 assert_kind_of String, version.text
80 104 end
81 105 end
82 106
83 107 def test_large_text_should_not_be_truncated_to_64k
84 108 page = WikiPage.new(:wiki => @wiki, :title => "Big page")
85 109 page.content = WikiContent.new(:text => "a" * 500.kilobyte, :author => User.find(1))
86 110 assert page.save
87 111 page.reload
88 112 assert_equal 500.kilobyte, page.content.text.size
89 113 end
90 114
91 115 def test_current_version
92 116 content = WikiContent.find(11)
93 117 assert_equal true, content.current_version?
94 118 assert_equal true, content.versions.first(:order => 'version DESC').current_version?
95 119 assert_equal false, content.versions.first(:order => 'version ASC').current_version?
96 120 end
97 121 end
General Comments 0
You need to be logged in to leave comments. Login now