comparison test/unit/helpers/issues_helper_test.rb @ 1526:404aa68d4227

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