Mercurial > hg > soundsoftware-site
comparison .svn/pristine/ae/ae03a6377d635b20cfaa05c6c3d5916b4077231a.svn-base @ 1517:dffacf8a6908 redmine-2.5
Update to Redmine SVN revision 13367 on 2.5-stable branch
author | Chris Cannam |
---|---|
date | Tue, 09 Sep 2014 09:29:00 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1516:b450a9d58aed | 1517:dffacf8a6908 |
---|---|
1 # Redmine - project management software | |
2 # Copyright (C) 2006-2014 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 :default_language => 'en', :notified_events => %w(wiki_content_added) do | |
52 assert page.save | |
53 end | |
54 | |
55 assert_equal 1, ActionMailer::Base.deliveries.size | |
56 assert_include 'wiki page has been added', mail_body(ActionMailer::Base.deliveries.last) | |
57 end | |
58 | |
59 def test_update_should_be_versioned | |
60 content = @page.content | |
61 version_count = content.version | |
62 content.text = "My new content" | |
63 assert_difference 'WikiContent::Version.count' do | |
64 assert content.save | |
65 end | |
66 content.reload | |
67 assert_equal version_count+1, content.version | |
68 assert_equal version_count+1, content.versions.length | |
69 | |
70 version = WikiContent::Version.order('id DESC').first | |
71 assert_equal @page.id, version.page_id | |
72 assert_equal '', version.compression | |
73 assert_equal "My new content", version.data | |
74 assert_equal "My new content", version.text | |
75 end | |
76 | |
77 def test_update_with_gzipped_history | |
78 with_settings :wiki_compression => 'gzip' do | |
79 content = @page.content | |
80 content.text = "My new content" | |
81 assert_difference 'WikiContent::Version.count' do | |
82 assert content.save | |
83 end | |
84 end | |
85 | |
86 version = WikiContent::Version.order('id DESC').first | |
87 assert_equal @page.id, version.page_id | |
88 assert_equal 'gzip', version.compression | |
89 assert_not_equal "My new content", version.data | |
90 assert_equal "My new content", version.text | |
91 end | |
92 | |
93 def test_update_should_send_email_notification | |
94 ActionMailer::Base.deliveries.clear | |
95 content = @page.content | |
96 content.text = "My new content" | |
97 | |
98 with_settings :notified_events => %w(wiki_content_updated) do | |
99 assert content.save | |
100 end | |
101 | |
102 assert_equal 1, ActionMailer::Base.deliveries.size | |
103 assert_include 'wiki page has been updated', mail_body(ActionMailer::Base.deliveries.last) | |
104 end | |
105 | |
106 def test_fetch_history | |
107 assert !@page.content.versions.empty? | |
108 @page.content.versions.each do |version| | |
109 assert_kind_of String, version.text | |
110 end | |
111 end | |
112 | |
113 def test_large_text_should_not_be_truncated_to_64k | |
114 page = WikiPage.new(:wiki => @wiki, :title => "Big page") | |
115 page.content = WikiContent.new(:text => "a" * 500.kilobyte, :author => User.find(1)) | |
116 assert page.save | |
117 page.reload | |
118 assert_equal 500.kilobyte, page.content.text.size | |
119 end | |
120 | |
121 def test_current_version | |
122 content = WikiContent.find(11) | |
123 assert_equal true, content.current_version? | |
124 assert_equal true, content.versions.order('version DESC').first.current_version? | |
125 assert_equal false, content.versions.order('version ASC').first.current_version? | |
126 end | |
127 | |
128 def test_previous_for_first_version_should_return_nil | |
129 content = WikiContent::Version.find_by_page_id_and_version(1, 1) | |
130 assert_nil content.previous | |
131 end | |
132 | |
133 def test_previous_for_version_should_return_previous_version | |
134 content = WikiContent::Version.find_by_page_id_and_version(1, 3) | |
135 assert_not_nil content.previous | |
136 assert_equal 2, content.previous.version | |
137 end | |
138 | |
139 def test_previous_for_version_with_gap_should_return_previous_available_version | |
140 WikiContent::Version.find_by_page_id_and_version(1, 2).destroy | |
141 | |
142 content = WikiContent::Version.find_by_page_id_and_version(1, 3) | |
143 assert_not_nil content.previous | |
144 assert_equal 1, content.previous.version | |
145 end | |
146 | |
147 def test_next_for_last_version_should_return_nil | |
148 content = WikiContent::Version.find_by_page_id_and_version(1, 3) | |
149 assert_nil content.next | |
150 end | |
151 | |
152 def test_next_for_version_should_return_next_version | |
153 content = WikiContent::Version.find_by_page_id_and_version(1, 1) | |
154 assert_not_nil content.next | |
155 assert_equal 2, content.next.version | |
156 end | |
157 | |
158 def test_next_for_version_with_gap_should_return_next_available_version | |
159 WikiContent::Version.find_by_page_id_and_version(1, 2).destroy | |
160 | |
161 content = WikiContent::Version.find_by_page_id_and_version(1, 1) | |
162 assert_not_nil content.next | |
163 assert_equal 3, content.next.version | |
164 end | |
165 end |