comparison .svn/pristine/ec/ecf9241c1e6ccd1ccee3ece4b5568fb173ad0940.svn-base @ 1464:261b3d9a4903 redmine-2.4

Update to Redmine 2.4 branch rev 12663
author Chris Cannam
date Tue, 14 Jan 2014 14:37:42 +0000
parents
children
comparison
equal deleted inserted replaced
1296:038ba2d95de8 1464:261b3d9a4903
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 IssuesHelperTest < ActionView::TestCase
21 include ApplicationHelper
22 include Redmine::I18n
23 include IssuesHelper
24 include CustomFieldsHelper
25 include ERB::Util
26
27 fixtures :projects, :trackers, :issue_statuses, :issues,
28 :enumerations, :users, :issue_categories,
29 :projects_trackers,
30 :roles,
31 :member_roles,
32 :members,
33 :enabled_modules,
34 :custom_fields,
35 :attachments,
36 :versions
37
38 def setup
39 super
40 set_language_if_valid('en')
41 User.current = nil
42 end
43
44 def test_issue_heading
45 assert_equal "Bug #1", issue_heading(Issue.find(1))
46 end
47
48 def test_issues_destroy_confirmation_message_with_one_root_issue
49 assert_equal l(:text_issues_destroy_confirmation),
50 issues_destroy_confirmation_message(Issue.find(1))
51 end
52
53 def test_issues_destroy_confirmation_message_with_an_arrayt_of_root_issues
54 assert_equal l(:text_issues_destroy_confirmation),
55 issues_destroy_confirmation_message(Issue.find([1, 2]))
56 end
57
58 def test_issues_destroy_confirmation_message_with_one_parent_issue
59 Issue.find(2).update_attribute :parent_issue_id, 1
60 assert_equal l(:text_issues_destroy_confirmation) + "\n" +
61 l(:text_issues_destroy_descendants_confirmation, :count => 1),
62 issues_destroy_confirmation_message(Issue.find(1))
63 end
64
65 def test_issues_destroy_confirmation_message_with_one_parent_issue_and_its_child
66 Issue.find(2).update_attribute :parent_issue_id, 1
67 assert_equal l(:text_issues_destroy_confirmation),
68 issues_destroy_confirmation_message(Issue.find([1, 2]))
69 end
70
71 test 'show_detail with no_html should show a changing attribute' do
72 detail = JournalDetail.new(:property => 'attr', :old_value => '40',
73 :value => '100', :prop_key => 'done_ratio')
74 assert_equal "% Done changed from 40 to 100", show_detail(detail, true)
75 end
76
77 test 'show_detail with no_html should show a new attribute' do
78 detail = JournalDetail.new(:property => 'attr', :old_value => nil,
79 :value => '100', :prop_key => 'done_ratio')
80 assert_equal "% Done set to 100", show_detail(detail, true)
81 end
82
83 test 'show_detail with no_html should show a deleted attribute' do
84 detail = JournalDetail.new(:property => 'attr', :old_value => '50',
85 :value => nil, :prop_key => 'done_ratio')
86 assert_equal "% Done deleted (50)", show_detail(detail, true)
87 end
88
89 test 'show_detail with html should show a changing attribute with HTML highlights' do
90 detail = JournalDetail.new(:property => 'attr', :old_value => '40',
91 :value => '100', :prop_key => 'done_ratio')
92 html = show_detail(detail, false)
93 assert_include '<strong>% Done</strong>', html
94 assert_include '<i>40</i>', html
95 assert_include '<i>100</i>', html
96 end
97
98 test 'show_detail with html should show a new attribute with HTML highlights' do
99 detail = JournalDetail.new(:property => 'attr', :old_value => nil,
100 :value => '100', :prop_key => 'done_ratio')
101 html = show_detail(detail, false)
102 assert_include '<strong>% Done</strong>', html
103 assert_include '<i>100</i>', html
104 end
105
106 test 'show_detail with html should show a deleted attribute with HTML highlights' do
107 detail = JournalDetail.new(:property => 'attr', :old_value => '50',
108 :value => nil, :prop_key => 'done_ratio')
109 html = show_detail(detail, false)
110 assert_include '<strong>% Done</strong>', html
111 assert_include '<del><i>50</i></del>', html
112 end
113
114 test 'show_detail with a start_date attribute should format the dates' do
115 detail = JournalDetail.new(
116 :property => 'attr',
117 :old_value => '2010-01-01',
118 :value => '2010-01-31',
119 :prop_key => 'start_date'
120 )
121 with_settings :date_format => '%m/%d/%Y' do
122 assert_match "01/31/2010", show_detail(detail, true)
123 assert_match "01/01/2010", show_detail(detail, true)
124 end
125 end
126
127 test 'show_detail with a due_date attribute should format the dates' do
128 detail = JournalDetail.new(
129 :property => 'attr',
130 :old_value => '2010-01-01',
131 :value => '2010-01-31',
132 :prop_key => 'due_date'
133 )
134 with_settings :date_format => '%m/%d/%Y' do
135 assert_match "01/31/2010", show_detail(detail, true)
136 assert_match "01/01/2010", show_detail(detail, true)
137 end
138 end
139
140 test 'show_detail should show old and new values with a project attribute' do
141 detail = JournalDetail.new(:property => 'attr', :prop_key => 'project_id',
142 :old_value => 1, :value => 2)
143 assert_match 'eCookbook', show_detail(detail, true)
144 assert_match 'OnlineStore', show_detail(detail, true)
145 end
146
147 test 'show_detail should show old and new values with a issue status attribute' do
148 detail = JournalDetail.new(:property => 'attr', :prop_key => 'status_id',
149 :old_value => 1, :value => 2)
150 assert_match 'New', show_detail(detail, true)
151 assert_match 'Assigned', show_detail(detail, true)
152 end
153
154 test 'show_detail should show old and new values with a tracker attribute' do
155 detail = JournalDetail.new(:property => 'attr', :prop_key => 'tracker_id',
156 :old_value => 1, :value => 2)
157 assert_match 'Bug', show_detail(detail, true)
158 assert_match 'Feature request', show_detail(detail, true)
159 end
160
161 test 'show_detail should show old and new values with a assigned to attribute' do
162 detail = JournalDetail.new(:property => 'attr', :prop_key => 'assigned_to_id',
163 :old_value => 1, :value => 2)
164 assert_match 'Redmine Admin', show_detail(detail, true)
165 assert_match 'John Smith', show_detail(detail, true)
166 end
167
168 test 'show_detail should show old and new values with a priority attribute' do
169 detail = JournalDetail.new(:property => 'attr', :prop_key => 'priority_id',
170 :old_value => 4, :value => 5)
171 assert_match 'Low', show_detail(detail, true)
172 assert_match 'Normal', show_detail(detail, true)
173 end
174
175 test 'show_detail should show old and new values with a category attribute' do
176 detail = JournalDetail.new(:property => 'attr', :prop_key => 'category_id',
177 :old_value => 1, :value => 2)
178 assert_match 'Printing', show_detail(detail, true)
179 assert_match 'Recipes', show_detail(detail, true)
180 end
181
182 test 'show_detail should show old and new values with a fixed version attribute' do
183 detail = JournalDetail.new(:property => 'attr', :prop_key => 'fixed_version_id',
184 :old_value => 1, :value => 2)
185 assert_match '0.1', show_detail(detail, true)
186 assert_match '1.0', show_detail(detail, true)
187 end
188
189 test 'show_detail should show old and new values with a estimated hours attribute' do
190 detail = JournalDetail.new(:property => 'attr', :prop_key => 'estimated_hours',
191 :old_value => '5', :value => '6.3')
192 assert_match '5.00', show_detail(detail, true)
193 assert_match '6.30', show_detail(detail, true)
194 end
195
196 test 'show_detail should show old and new values with a custom field' do
197 detail = JournalDetail.new(:property => 'cf', :prop_key => '1',
198 :old_value => 'MySQL', :value => 'PostgreSQL')
199 assert_equal 'Database changed from MySQL to PostgreSQL', show_detail(detail, true)
200 end
201
202 test 'show_detail should show added file' do
203 detail = JournalDetail.new(:property => 'attachment', :prop_key => '1',
204 :old_value => nil, :value => 'error281.txt')
205 assert_match 'error281.txt', show_detail(detail, true)
206 end
207
208 test 'show_detail should show removed file' do
209 detail = JournalDetail.new(:property => 'attachment', :prop_key => '1',
210 :old_value => 'error281.txt', :value => nil)
211 assert_match 'error281.txt', show_detail(detail, true)
212 end
213
214 def test_show_detail_relation_added
215 detail = JournalDetail.new(:property => 'relation',
216 :prop_key => 'label_precedes',
217 :value => 1)
218 assert_equal "Precedes Bug #1: Can't print recipes added", show_detail(detail, true)
219 assert_match %r{<strong>Precedes</strong> <i><a href="/issues/1" class=".+">Bug #1</a>: Can&#x27;t print recipes</i> added},
220 show_detail(detail, false)
221 end
222
223 def test_show_detail_relation_added_with_inexistant_issue
224 inexistant_issue_number = 9999
225 assert_nil Issue.find_by_id(inexistant_issue_number)
226 detail = JournalDetail.new(:property => 'relation',
227 :prop_key => 'label_precedes',
228 :value => inexistant_issue_number)
229 assert_equal "Precedes Issue ##{inexistant_issue_number} added", show_detail(detail, true)
230 assert_equal "<strong>Precedes</strong> <i>Issue ##{inexistant_issue_number}</i> added", show_detail(detail, false)
231 end
232
233 def test_show_detail_relation_added_should_not_disclose_issue_that_is_not_visible
234 issue = Issue.generate!(:is_private => true)
235 detail = JournalDetail.new(:property => 'relation',
236 :prop_key => 'label_precedes',
237 :value => issue.id)
238
239 assert_equal "Precedes Issue ##{issue.id} added", show_detail(detail, true)
240 assert_equal "<strong>Precedes</strong> <i>Issue ##{issue.id}</i> added", show_detail(detail, false)
241 end
242
243 def test_show_detail_relation_deleted
244 detail = JournalDetail.new(:property => 'relation',
245 :prop_key => 'label_precedes',
246 :old_value => 1)
247 assert_equal "Precedes deleted (Bug #1: Can't print recipes)", show_detail(detail, true)
248 assert_match %r{<strong>Precedes</strong> deleted \(<i><a href="/issues/1" class=".+">Bug #1</a>: Can&#x27;t print recipes</i>\)},
249 show_detail(detail, false)
250 end
251
252 def test_show_detail_relation_deleted_with_inexistant_issue
253 inexistant_issue_number = 9999
254 assert_nil Issue.find_by_id(inexistant_issue_number)
255 detail = JournalDetail.new(:property => 'relation',
256 :prop_key => 'label_precedes',
257 :old_value => inexistant_issue_number)
258 assert_equal "Precedes deleted (Issue #9999)", show_detail(detail, true)
259 assert_equal "<strong>Precedes</strong> deleted (<i>Issue #9999</i>)", show_detail(detail, false)
260 end
261
262 def test_show_detail_relation_deleted_should_not_disclose_issue_that_is_not_visible
263 issue = Issue.generate!(:is_private => true)
264 detail = JournalDetail.new(:property => 'relation',
265 :prop_key => 'label_precedes',
266 :old_value => issue.id)
267
268 assert_equal "Precedes deleted (Issue ##{issue.id})", show_detail(detail, true)
269 assert_equal "<strong>Precedes</strong> deleted (<i>Issue ##{issue.id}</i>)", show_detail(detail, false)
270 end
271 end