comparison .svn/pristine/5f/5f0eae515ed184a3480763e5de7b865ac6400930.svn-base @ 1298:4f746d8966dd redmine_2.3_integration

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