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