##// END OF EJS Templates
Slight changes in functional tests....
Jean-Philippe Lang -
r2233:cd83f72da47f
parent child
Show More
@@ -1,124 +1,124
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 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.dirname(__FILE__) + '/../test_helper'
19 19 require 'admin_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class AdminController; def rescue_action(e) raise e end; end
23 23
24 24 class AdminControllerTest < Test::Unit::TestCase
25 25 fixtures :projects, :users, :roles
26 26
27 27 def setup
28 28 @controller = AdminController.new
29 29 @request = ActionController::TestRequest.new
30 30 @response = ActionController::TestResponse.new
31 31 User.current = nil
32 32 @request.session[:user_id] = 1 # admin
33 33 end
34 34
35 35 def test_index
36 36 get :index
37 37 assert_no_tag :tag => 'div',
38 38 :attributes => { :class => /nodata/ }
39 39 end
40 40
41 41 def test_index_with_no_configuration_data
42 42 delete_configuration_data
43 43 get :index
44 44 assert_tag :tag => 'div',
45 45 :attributes => { :class => /nodata/ }
46 46 end
47 47
48 48 def test_projects
49 49 get :projects
50 50 assert_response :success
51 51 assert_template 'projects'
52 52 assert_not_nil assigns(:projects)
53 53 # active projects only
54 54 assert_nil assigns(:projects).detect {|u| !u.active?}
55 55 end
56 56
57 57 def test_projects_with_name_filter
58 58 get :projects, :name => 'store', :status => ''
59 59 assert_response :success
60 60 assert_template 'projects'
61 61 projects = assigns(:projects)
62 62 assert_not_nil projects
63 63 assert_equal 1, projects.size
64 64 assert_equal 'OnlineStore', projects.first.name
65 65 end
66 66
67 67 def test_load_default_configuration_data
68 68 delete_configuration_data
69 69 post :default_configuration, :lang => 'fr'
70 70 assert IssueStatus.find_by_name('Nouveau')
71 71 end
72 72
73 73 def test_test_email
74 74 get :test_email
75 assert_redirected_to 'settings/edit'
75 assert_redirected_to '/settings/edit?tab=notifications'
76 76 mail = ActionMailer::Base.deliveries.last
77 77 assert_kind_of TMail::Mail, mail
78 78 user = User.find(1)
79 79 assert_equal [user.mail], mail.bcc
80 80 end
81 81
82 82 def test_no_plugins
83 83 Redmine::Plugin.clear
84 84
85 85 get :plugins
86 86 assert_response :success
87 87 assert_template 'plugins'
88 88 end
89 89
90 90 def test_plugins
91 91 # Register a few plugins
92 92 Redmine::Plugin.register :foo do
93 93 name 'Foo plugin'
94 94 author 'John Smith'
95 95 description 'This is a test plugin'
96 96 version '0.0.1'
97 97 settings :default => {'sample_setting' => 'value', 'foo'=>'bar'}, :partial => 'foo/settings'
98 98 end
99 99 Redmine::Plugin.register :bar do
100 100 end
101 101
102 102 get :plugins
103 103 assert_response :success
104 104 assert_template 'plugins'
105 105
106 106 assert_tag :td, :child => { :tag => 'span', :content => 'Foo plugin' }
107 107 assert_tag :td, :child => { :tag => 'span', :content => 'Bar' }
108 108 end
109 109
110 110 def test_info
111 111 get :info
112 112 assert_response :success
113 113 assert_template 'info'
114 114 end
115 115
116 116 private
117 117
118 118 def delete_configuration_data
119 119 Role.delete_all('builtin = 0')
120 120 Tracker.delete_all
121 121 IssueStatus.delete_all
122 122 Enumeration.delete_all
123 123 end
124 124 end
@@ -1,126 +1,126
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2008 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.dirname(__FILE__) + '/../test_helper'
19 19 require 'attachments_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class AttachmentsController; def rescue_action(e) raise e end; end
23 23
24 24
25 25 class AttachmentsControllerTest < Test::Unit::TestCase
26 26 fixtures :users, :projects, :roles, :members, :enabled_modules, :issues, :attachments,
27 27 :versions, :wiki_pages, :wikis
28 28
29 29 def setup
30 30 @controller = AttachmentsController.new
31 31 @request = ActionController::TestRequest.new
32 32 @response = ActionController::TestResponse.new
33 33 Attachment.storage_path = "#{RAILS_ROOT}/test/fixtures/files"
34 34 User.current = nil
35 35 end
36 36
37 37 def test_routing
38 38 assert_routing('/attachments/1', :controller => 'attachments', :action => 'show', :id => '1')
39 39 assert_routing('/attachments/1/filename.ext', :controller => 'attachments', :action => 'show', :id => '1', :filename => 'filename.ext')
40 40 assert_routing('/attachments/download/1', :controller => 'attachments', :action => 'download', :id => '1')
41 41 assert_routing('/attachments/download/1/filename.ext', :controller => 'attachments', :action => 'download', :id => '1', :filename => 'filename.ext')
42 42 end
43 43
44 44 def test_recognizes
45 45 assert_recognizes({:controller => 'attachments', :action => 'show', :id => '1'}, '/attachments/1')
46 46 assert_recognizes({:controller => 'attachments', :action => 'show', :id => '1'}, '/attachments/show/1')
47 47 assert_recognizes({:controller => 'attachments', :action => 'show', :id => '1', :filename => 'filename.ext'}, '/attachments/1/filename.ext')
48 48 assert_recognizes({:controller => 'attachments', :action => 'download', :id => '1'}, '/attachments/download/1')
49 49 assert_recognizes({:controller => 'attachments', :action => 'download', :id => '1', :filename => 'filename.ext'},'/attachments/download/1/filename.ext')
50 50 end
51 51
52 52 def test_show_diff
53 53 get :show, :id => 5
54 54 assert_response :success
55 55 assert_template 'diff'
56 56 end
57 57
58 58 def test_show_text_file
59 59 get :show, :id => 4
60 60 assert_response :success
61 61 assert_template 'file'
62 62 end
63 63
64 64 def test_show_other
65 65 get :show, :id => 6
66 66 assert_response :success
67 67 assert_equal 'application/octet-stream', @response.content_type
68 68 end
69 69
70 70 def test_download_text_file
71 71 get :download, :id => 4
72 72 assert_response :success
73 73 assert_equal 'application/x-ruby', @response.content_type
74 74 end
75 75
76 76 def test_anonymous_on_private_private
77 77 get :download, :id => 7
78 assert_redirected_to 'account/login'
78 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdownload%2F7'
79 79 end
80 80
81 81 def test_destroy_issue_attachment
82 82 issue = Issue.find(3)
83 83 @request.session[:user_id] = 2
84 84
85 85 assert_difference 'issue.attachments.count', -1 do
86 86 post :destroy, :id => 1
87 87 end
88 88 # no referrer
89 89 assert_redirected_to 'projects/show/ecookbook'
90 90 assert_nil Attachment.find_by_id(1)
91 91 j = issue.journals.find(:first, :order => 'created_on DESC')
92 92 assert_equal 'attachment', j.details.first.property
93 93 assert_equal '1', j.details.first.prop_key
94 94 assert_equal 'error281.txt', j.details.first.old_value
95 95 end
96 96
97 97 def test_destroy_wiki_page_attachment
98 98 @request.session[:user_id] = 2
99 99 assert_difference 'Attachment.count', -1 do
100 100 post :destroy, :id => 3
101 101 assert_response 302
102 102 end
103 103 end
104 104
105 105 def test_destroy_project_attachment
106 106 @request.session[:user_id] = 2
107 107 assert_difference 'Attachment.count', -1 do
108 108 post :destroy, :id => 8
109 109 assert_response 302
110 110 end
111 111 end
112 112
113 113 def test_destroy_version_attachment
114 114 @request.session[:user_id] = 2
115 115 assert_difference 'Attachment.count', -1 do
116 116 post :destroy, :id => 9
117 117 assert_response 302
118 118 end
119 119 end
120 120
121 121 def test_destroy_without_permission
122 122 post :destroy, :id => 3
123 assert_redirected_to '/login'
123 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdestroy%2F3'
124 124 assert Attachment.find_by_id(3)
125 125 end
126 126 end
@@ -1,758 +1,759
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2008 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.dirname(__FILE__) + '/../test_helper'
19 19 require 'issues_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class IssuesController; def rescue_action(e) raise e end; end
23 23
24 24 class IssuesControllerTest < Test::Unit::TestCase
25 25 fixtures :projects,
26 26 :users,
27 27 :roles,
28 28 :members,
29 29 :issues,
30 30 :issue_statuses,
31 31 :versions,
32 32 :trackers,
33 33 :projects_trackers,
34 34 :issue_categories,
35 35 :enabled_modules,
36 36 :enumerations,
37 37 :attachments,
38 38 :workflows,
39 39 :custom_fields,
40 40 :custom_values,
41 41 :custom_fields_trackers,
42 42 :time_entries,
43 43 :journals,
44 44 :journal_details
45 45
46 46 def setup
47 47 @controller = IssuesController.new
48 48 @request = ActionController::TestRequest.new
49 49 @response = ActionController::TestResponse.new
50 50 User.current = nil
51 51 end
52 52
53 53 def test_index
54 54 get :index
55 55 assert_response :success
56 56 assert_template 'index.rhtml'
57 57 assert_not_nil assigns(:issues)
58 58 assert_nil assigns(:project)
59 59 assert_tag :tag => 'a', :content => /Can't print recipes/
60 60 assert_tag :tag => 'a', :content => /Subproject issue/
61 61 # private projects hidden
62 62 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
63 63 assert_no_tag :tag => 'a', :content => /Issue on project 2/
64 64 end
65 65
66 66 def test_index_should_not_list_issues_when_module_disabled
67 67 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
68 68 get :index
69 69 assert_response :success
70 70 assert_template 'index.rhtml'
71 71 assert_not_nil assigns(:issues)
72 72 assert_nil assigns(:project)
73 73 assert_no_tag :tag => 'a', :content => /Can't print recipes/
74 74 assert_tag :tag => 'a', :content => /Subproject issue/
75 75 end
76 76
77 77 def test_index_with_project
78 78 Setting.display_subprojects_issues = 0
79 79 get :index, :project_id => 1
80 80 assert_response :success
81 81 assert_template 'index.rhtml'
82 82 assert_not_nil assigns(:issues)
83 83 assert_tag :tag => 'a', :content => /Can't print recipes/
84 84 assert_no_tag :tag => 'a', :content => /Subproject issue/
85 85 end
86 86
87 87 def test_index_with_project_and_subprojects
88 88 Setting.display_subprojects_issues = 1
89 89 get :index, :project_id => 1
90 90 assert_response :success
91 91 assert_template 'index.rhtml'
92 92 assert_not_nil assigns(:issues)
93 93 assert_tag :tag => 'a', :content => /Can't print recipes/
94 94 assert_tag :tag => 'a', :content => /Subproject issue/
95 95 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
96 96 end
97 97
98 98 def test_index_with_project_and_subprojects_should_show_private_subprojects
99 99 @request.session[:user_id] = 2
100 100 Setting.display_subprojects_issues = 1
101 101 get :index, :project_id => 1
102 102 assert_response :success
103 103 assert_template 'index.rhtml'
104 104 assert_not_nil assigns(:issues)
105 105 assert_tag :tag => 'a', :content => /Can't print recipes/
106 106 assert_tag :tag => 'a', :content => /Subproject issue/
107 107 assert_tag :tag => 'a', :content => /Issue of a private subproject/
108 108 end
109 109
110 110 def test_index_with_project_and_filter
111 111 get :index, :project_id => 1, :set_filter => 1
112 112 assert_response :success
113 113 assert_template 'index.rhtml'
114 114 assert_not_nil assigns(:issues)
115 115 end
116 116
117 117 def test_index_csv_with_project
118 118 get :index, :format => 'csv'
119 119 assert_response :success
120 120 assert_not_nil assigns(:issues)
121 121 assert_equal 'text/csv', @response.content_type
122 122
123 123 get :index, :project_id => 1, :format => 'csv'
124 124 assert_response :success
125 125 assert_not_nil assigns(:issues)
126 126 assert_equal 'text/csv', @response.content_type
127 127 end
128 128
129 129 def test_index_pdf
130 130 get :index, :format => 'pdf'
131 131 assert_response :success
132 132 assert_not_nil assigns(:issues)
133 133 assert_equal 'application/pdf', @response.content_type
134 134
135 135 get :index, :project_id => 1, :format => 'pdf'
136 136 assert_response :success
137 137 assert_not_nil assigns(:issues)
138 138 assert_equal 'application/pdf', @response.content_type
139 139 end
140 140
141 141 def test_index_sort
142 142 get :index, :sort_key => 'tracker'
143 143 assert_response :success
144 144
145 145 sort_params = @request.session['issuesindex_sort']
146 146 assert sort_params.is_a?(Hash)
147 147 assert_equal 'tracker', sort_params[:key]
148 148 assert_equal 'ASC', sort_params[:order]
149 149 end
150 150
151 151 def test_gantt
152 152 get :gantt, :project_id => 1
153 153 assert_response :success
154 154 assert_template 'gantt.rhtml'
155 155 assert_not_nil assigns(:gantt)
156 156 events = assigns(:gantt).events
157 157 assert_not_nil events
158 158 # Issue with start and due dates
159 159 i = Issue.find(1)
160 160 assert_not_nil i.due_date
161 161 assert events.include?(Issue.find(1))
162 162 # Issue with without due date but targeted to a version with date
163 163 i = Issue.find(2)
164 164 assert_nil i.due_date
165 165 assert events.include?(i)
166 166 end
167 167
168 168 def test_cross_project_gantt
169 169 get :gantt
170 170 assert_response :success
171 171 assert_template 'gantt.rhtml'
172 172 assert_not_nil assigns(:gantt)
173 173 events = assigns(:gantt).events
174 174 assert_not_nil events
175 175 end
176 176
177 177 def test_gantt_export_to_pdf
178 178 get :gantt, :project_id => 1, :format => 'pdf'
179 179 assert_response :success
180 180 assert_equal 'application/pdf', @response.content_type
181 181 assert @response.body.starts_with?('%PDF')
182 182 assert_not_nil assigns(:gantt)
183 183 end
184 184
185 185 def test_cross_project_gantt_export_to_pdf
186 186 get :gantt, :format => 'pdf'
187 187 assert_response :success
188 188 assert_equal 'application/pdf', @response.content_type
189 189 assert @response.body.starts_with?('%PDF')
190 190 assert_not_nil assigns(:gantt)
191 191 end
192 192
193 193 if Object.const_defined?(:Magick)
194 194 def test_gantt_image
195 195 get :gantt, :project_id => 1, :format => 'png'
196 196 assert_response :success
197 197 assert_equal 'image/png', @response.content_type
198 198 end
199 199 else
200 200 puts "RMagick not installed. Skipping tests !!!"
201 201 end
202 202
203 203 def test_calendar
204 204 get :calendar, :project_id => 1
205 205 assert_response :success
206 206 assert_template 'calendar'
207 207 assert_not_nil assigns(:calendar)
208 208 end
209 209
210 210 def test_cross_project_calendar
211 211 get :calendar
212 212 assert_response :success
213 213 assert_template 'calendar'
214 214 assert_not_nil assigns(:calendar)
215 215 end
216 216
217 217 def test_changes
218 218 get :changes, :project_id => 1
219 219 assert_response :success
220 220 assert_not_nil assigns(:journals)
221 221 assert_equal 'application/atom+xml', @response.content_type
222 222 end
223 223
224 224 def test_show_by_anonymous
225 225 get :show, :id => 1
226 226 assert_response :success
227 227 assert_template 'show.rhtml'
228 228 assert_not_nil assigns(:issue)
229 229 assert_equal Issue.find(1), assigns(:issue)
230 230
231 231 # anonymous role is allowed to add a note
232 232 assert_tag :tag => 'form',
233 233 :descendant => { :tag => 'fieldset',
234 234 :child => { :tag => 'legend',
235 235 :content => /Notes/ } }
236 236 end
237 237
238 238 def test_show_by_manager
239 239 @request.session[:user_id] = 2
240 240 get :show, :id => 1
241 241 assert_response :success
242 242
243 243 assert_tag :tag => 'form',
244 244 :descendant => { :tag => 'fieldset',
245 245 :child => { :tag => 'legend',
246 246 :content => /Change properties/ } },
247 247 :descendant => { :tag => 'fieldset',
248 248 :child => { :tag => 'legend',
249 249 :content => /Log time/ } },
250 250 :descendant => { :tag => 'fieldset',
251 251 :child => { :tag => 'legend',
252 252 :content => /Notes/ } }
253 253 end
254 254
255 255 def test_show_export_to_pdf
256 256 get :show, :id => 1, :format => 'pdf'
257 257 assert_response :success
258 258 assert_equal 'application/pdf', @response.content_type
259 259 assert @response.body.starts_with?('%PDF')
260 260 assert_not_nil assigns(:issue)
261 261 end
262 262
263 263 def test_get_new
264 264 @request.session[:user_id] = 2
265 265 get :new, :project_id => 1, :tracker_id => 1
266 266 assert_response :success
267 267 assert_template 'new'
268 268
269 269 assert_tag :tag => 'input', :attributes => { :name => 'issue[custom_field_values][2]',
270 270 :value => 'Default string' }
271 271 end
272 272
273 273 def test_get_new_without_tracker_id
274 274 @request.session[:user_id] = 2
275 275 get :new, :project_id => 1
276 276 assert_response :success
277 277 assert_template 'new'
278 278
279 279 issue = assigns(:issue)
280 280 assert_not_nil issue
281 281 assert_equal Project.find(1).trackers.first, issue.tracker
282 282 end
283 283
284 284 def test_update_new_form
285 285 @request.session[:user_id] = 2
286 286 xhr :post, :new, :project_id => 1,
287 287 :issue => {:tracker_id => 2,
288 288 :subject => 'This is the test_new issue',
289 289 :description => 'This is the description',
290 290 :priority_id => 5}
291 291 assert_response :success
292 292 assert_template 'new'
293 293 end
294 294
295 295 def test_post_new
296 296 @request.session[:user_id] = 2
297 297 post :new, :project_id => 1,
298 298 :issue => {:tracker_id => 3,
299 299 :subject => 'This is the test_new issue',
300 300 :description => 'This is the description',
301 301 :priority_id => 5,
302 302 :estimated_hours => '',
303 303 :custom_field_values => {'2' => 'Value for field 2'}}
304 assert_redirected_to 'issues/show'
304 assert_redirected_to :controller => 'issues', :action => 'show'
305 305
306 306 issue = Issue.find_by_subject('This is the test_new issue')
307 307 assert_not_nil issue
308 308 assert_equal 2, issue.author_id
309 309 assert_equal 3, issue.tracker_id
310 310 assert_nil issue.estimated_hours
311 311 v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2})
312 312 assert_not_nil v
313 313 assert_equal 'Value for field 2', v.value
314 314 end
315 315
316 316 def test_post_new_without_custom_fields_param
317 317 @request.session[:user_id] = 2
318 318 post :new, :project_id => 1,
319 319 :issue => {:tracker_id => 1,
320 320 :subject => 'This is the test_new issue',
321 321 :description => 'This is the description',
322 322 :priority_id => 5}
323 assert_redirected_to 'issues/show'
323 assert_redirected_to :controller => 'issues', :action => 'show'
324 324 end
325 325
326 326 def test_post_new_with_required_custom_field_and_without_custom_fields_param
327 327 field = IssueCustomField.find_by_name('Database')
328 328 field.update_attribute(:is_required, true)
329 329
330 330 @request.session[:user_id] = 2
331 331 post :new, :project_id => 1,
332 332 :issue => {:tracker_id => 1,
333 333 :subject => 'This is the test_new issue',
334 334 :description => 'This is the description',
335 335 :priority_id => 5}
336 336 assert_response :success
337 337 assert_template 'new'
338 338 issue = assigns(:issue)
339 339 assert_not_nil issue
340 340 assert_equal 'activerecord_error_invalid', issue.errors.on(:custom_values)
341 341 end
342 342
343 343 def test_post_new_with_watchers
344 344 @request.session[:user_id] = 2
345 345 ActionMailer::Base.deliveries.clear
346 346
347 347 assert_difference 'Watcher.count', 2 do
348 348 post :new, :project_id => 1,
349 349 :issue => {:tracker_id => 1,
350 350 :subject => 'This is a new issue with watchers',
351 351 :description => 'This is the description',
352 352 :priority_id => 5,
353 353 :watcher_user_ids => ['2', '3']}
354 354 end
355 assert_redirected_to 'issues/show'
356
357 355 issue = Issue.find_by_subject('This is a new issue with watchers')
356 assert_not_nil issue
357 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
358
358 359 # Watchers added
359 360 assert_equal [2, 3], issue.watcher_user_ids.sort
360 361 assert issue.watched_by?(User.find(3))
361 362 # Watchers notified
362 363 mail = ActionMailer::Base.deliveries.last
363 364 assert_kind_of TMail::Mail, mail
364 365 assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail)
365 366 end
366 367
367 368 def test_post_should_preserve_fields_values_on_validation_failure
368 369 @request.session[:user_id] = 2
369 370 post :new, :project_id => 1,
370 371 :issue => {:tracker_id => 1,
371 372 :subject => 'This is the test_new issue',
372 373 # empty description
373 374 :description => '',
374 375 :priority_id => 6,
375 376 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}}
376 377 assert_response :success
377 378 assert_template 'new'
378 379
379 380 assert_tag :input, :attributes => { :name => 'issue[subject]',
380 381 :value => 'This is the test_new issue' }
381 382 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
382 383 :child => { :tag => 'option', :attributes => { :selected => 'selected',
383 384 :value => '6' },
384 385 :content => 'High' }
385 386 # Custom fields
386 387 assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' },
387 388 :child => { :tag => 'option', :attributes => { :selected => 'selected',
388 389 :value => 'Oracle' },
389 390 :content => 'Oracle' }
390 391 assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]',
391 392 :value => 'Value for field 2'}
392 393 end
393 394
394 395 def test_copy_issue
395 396 @request.session[:user_id] = 2
396 397 get :new, :project_id => 1, :copy_from => 1
397 398 assert_template 'new'
398 399 assert_not_nil assigns(:issue)
399 400 orig = Issue.find(1)
400 401 assert_equal orig.subject, assigns(:issue).subject
401 402 end
402 403
403 404 def test_get_edit
404 405 @request.session[:user_id] = 2
405 406 get :edit, :id => 1
406 407 assert_response :success
407 408 assert_template 'edit'
408 409 assert_not_nil assigns(:issue)
409 410 assert_equal Issue.find(1), assigns(:issue)
410 411 end
411 412
412 413 def test_get_edit_with_params
413 414 @request.session[:user_id] = 2
414 415 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 }
415 416 assert_response :success
416 417 assert_template 'edit'
417 418
418 419 issue = assigns(:issue)
419 420 assert_not_nil issue
420 421
421 422 assert_equal 5, issue.status_id
422 423 assert_tag :select, :attributes => { :name => 'issue[status_id]' },
423 424 :child => { :tag => 'option',
424 425 :content => 'Closed',
425 426 :attributes => { :selected => 'selected' } }
426 427
427 428 assert_equal 7, issue.priority_id
428 429 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
429 430 :child => { :tag => 'option',
430 431 :content => 'Urgent',
431 432 :attributes => { :selected => 'selected' } }
432 433 end
433 434
434 435 def test_reply_to_issue
435 436 @request.session[:user_id] = 2
436 437 get :reply, :id => 1
437 438 assert_response :success
438 439 assert_select_rjs :show, "update"
439 440 end
440 441
441 442 def test_reply_to_note
442 443 @request.session[:user_id] = 2
443 444 get :reply, :id => 1, :journal_id => 2
444 445 assert_response :success
445 446 assert_select_rjs :show, "update"
446 447 end
447 448
448 449 def test_post_edit_without_custom_fields_param
449 450 @request.session[:user_id] = 2
450 451 ActionMailer::Base.deliveries.clear
451 452
452 453 issue = Issue.find(1)
453 454 assert_equal '125', issue.custom_value_for(2).value
454 455 old_subject = issue.subject
455 456 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
456 457
457 458 assert_difference('Journal.count') do
458 459 assert_difference('JournalDetail.count', 2) do
459 460 post :edit, :id => 1, :issue => {:subject => new_subject,
460 461 :priority_id => '6',
461 462 :category_id => '1' # no change
462 463 }
463 464 end
464 465 end
465 466 assert_redirected_to 'issues/show/1'
466 467 issue.reload
467 468 assert_equal new_subject, issue.subject
468 469 # Make sure custom fields were not cleared
469 470 assert_equal '125', issue.custom_value_for(2).value
470 471
471 472 mail = ActionMailer::Base.deliveries.last
472 473 assert_kind_of TMail::Mail, mail
473 474 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
474 475 assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}")
475 476 end
476 477
477 478 def test_post_edit_with_custom_field_change
478 479 @request.session[:user_id] = 2
479 480 issue = Issue.find(1)
480 481 assert_equal '125', issue.custom_value_for(2).value
481 482
482 483 assert_difference('Journal.count') do
483 484 assert_difference('JournalDetail.count', 3) do
484 485 post :edit, :id => 1, :issue => {:subject => 'Custom field change',
485 486 :priority_id => '6',
486 487 :category_id => '1', # no change
487 488 :custom_field_values => { '2' => 'New custom value' }
488 489 }
489 490 end
490 491 end
491 492 assert_redirected_to 'issues/show/1'
492 493 issue.reload
493 494 assert_equal 'New custom value', issue.custom_value_for(2).value
494 495
495 496 mail = ActionMailer::Base.deliveries.last
496 497 assert_kind_of TMail::Mail, mail
497 498 assert mail.body.include?("Searchable field changed from 125 to New custom value")
498 499 end
499 500
500 501 def test_post_edit_with_status_and_assignee_change
501 502 issue = Issue.find(1)
502 503 assert_equal 1, issue.status_id
503 504 @request.session[:user_id] = 2
504 505 assert_difference('TimeEntry.count', 0) do
505 506 post :edit,
506 507 :id => 1,
507 508 :issue => { :status_id => 2, :assigned_to_id => 3 },
508 509 :notes => 'Assigned to dlopper',
509 510 :time_entry => { :hours => '', :comments => '', :activity_id => Enumeration.get_values('ACTI').first }
510 511 end
511 512 assert_redirected_to 'issues/show/1'
512 513 issue.reload
513 514 assert_equal 2, issue.status_id
514 515 j = issue.journals.find(:first, :order => 'id DESC')
515 516 assert_equal 'Assigned to dlopper', j.notes
516 517 assert_equal 2, j.details.size
517 518
518 519 mail = ActionMailer::Base.deliveries.last
519 520 assert mail.body.include?("Status changed from New to Assigned")
520 521 end
521 522
522 523 def test_post_edit_with_note_only
523 524 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
524 525 # anonymous user
525 526 post :edit,
526 527 :id => 1,
527 528 :notes => notes
528 529 assert_redirected_to 'issues/show/1'
529 530 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
530 531 assert_equal notes, j.notes
531 532 assert_equal 0, j.details.size
532 533 assert_equal User.anonymous, j.user
533 534
534 535 mail = ActionMailer::Base.deliveries.last
535 536 assert mail.body.include?(notes)
536 537 end
537 538
538 539 def test_post_edit_with_note_and_spent_time
539 540 @request.session[:user_id] = 2
540 541 spent_hours_before = Issue.find(1).spent_hours
541 542 assert_difference('TimeEntry.count') do
542 543 post :edit,
543 544 :id => 1,
544 545 :notes => '2.5 hours added',
545 546 :time_entry => { :hours => '2.5', :comments => '', :activity_id => Enumeration.get_values('ACTI').first }
546 547 end
547 548 assert_redirected_to 'issues/show/1'
548 549
549 550 issue = Issue.find(1)
550 551
551 552 j = issue.journals.find(:first, :order => 'id DESC')
552 553 assert_equal '2.5 hours added', j.notes
553 554 assert_equal 0, j.details.size
554 555
555 556 t = issue.time_entries.find(:first, :order => 'id DESC')
556 557 assert_not_nil t
557 558 assert_equal 2.5, t.hours
558 559 assert_equal spent_hours_before + 2.5, issue.spent_hours
559 560 end
560 561
561 562 def test_post_edit_with_attachment_only
562 563 set_tmp_attachments_directory
563 564
564 565 # Delete all fixtured journals, a race condition can occur causing the wrong
565 566 # journal to get fetched in the next find.
566 567 Journal.delete_all
567 568
568 569 # anonymous user
569 570 post :edit,
570 571 :id => 1,
571 572 :notes => '',
572 573 :attachments => {'1' => {'file' => test_uploaded_file('testfile.txt', 'text/plain')}}
573 574 assert_redirected_to 'issues/show/1'
574 575 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
575 576 assert j.notes.blank?
576 577 assert_equal 1, j.details.size
577 578 assert_equal 'testfile.txt', j.details.first.value
578 579 assert_equal User.anonymous, j.user
579 580
580 581 mail = ActionMailer::Base.deliveries.last
581 582 assert mail.body.include?('testfile.txt')
582 583 end
583 584
584 585 def test_post_edit_with_no_change
585 586 issue = Issue.find(1)
586 587 issue.journals.clear
587 588 ActionMailer::Base.deliveries.clear
588 589
589 590 post :edit,
590 591 :id => 1,
591 592 :notes => ''
592 593 assert_redirected_to 'issues/show/1'
593 594
594 595 issue.reload
595 596 assert issue.journals.empty?
596 597 # No email should be sent
597 598 assert ActionMailer::Base.deliveries.empty?
598 599 end
599 600
600 601 def test_bulk_edit
601 602 @request.session[:user_id] = 2
602 603 # update issues priority
603 604 post :bulk_edit, :ids => [1, 2], :priority_id => 7, :notes => 'Bulk editing', :assigned_to_id => ''
604 605 assert_response 302
605 606 # check that the issues were updated
606 607 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
607 608 assert_equal 'Bulk editing', Issue.find(1).journals.find(:first, :order => 'created_on DESC').notes
608 609 end
609 610
610 611 def test_bulk_unassign
611 612 assert_not_nil Issue.find(2).assigned_to
612 613 @request.session[:user_id] = 2
613 614 # unassign issues
614 615 post :bulk_edit, :ids => [1, 2], :notes => 'Bulk unassigning', :assigned_to_id => 'none'
615 616 assert_response 302
616 617 # check that the issues were updated
617 618 assert_nil Issue.find(2).assigned_to
618 619 end
619 620
620 621 def test_move_one_issue_to_another_project
621 622 @request.session[:user_id] = 1
622 623 post :move, :id => 1, :new_project_id => 2
623 624 assert_redirected_to 'projects/ecookbook/issues'
624 625 assert_equal 2, Issue.find(1).project_id
625 626 end
626 627
627 628 def test_bulk_move_to_another_project
628 629 @request.session[:user_id] = 1
629 630 post :move, :ids => [1, 2], :new_project_id => 2
630 631 assert_redirected_to 'projects/ecookbook/issues'
631 632 # Issues moved to project 2
632 633 assert_equal 2, Issue.find(1).project_id
633 634 assert_equal 2, Issue.find(2).project_id
634 635 # No tracker change
635 636 assert_equal 1, Issue.find(1).tracker_id
636 637 assert_equal 2, Issue.find(2).tracker_id
637 638 end
638 639
639 640 def test_bulk_move_to_another_tracker
640 641 @request.session[:user_id] = 1
641 642 post :move, :ids => [1, 2], :new_tracker_id => 2
642 643 assert_redirected_to 'projects/ecookbook/issues'
643 644 assert_equal 2, Issue.find(1).tracker_id
644 645 assert_equal 2, Issue.find(2).tracker_id
645 646 end
646 647
647 648 def test_context_menu_one_issue
648 649 @request.session[:user_id] = 2
649 650 get :context_menu, :ids => [1]
650 651 assert_response :success
651 652 assert_template 'context_menu'
652 653 assert_tag :tag => 'a', :content => 'Edit',
653 654 :attributes => { :href => '/issues/edit/1',
654 655 :class => 'icon-edit' }
655 656 assert_tag :tag => 'a', :content => 'Closed',
656 657 :attributes => { :href => '/issues/edit/1?issue%5Bstatus_id%5D=5',
657 658 :class => '' }
658 659 assert_tag :tag => 'a', :content => 'Immediate',
659 660 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;priority_id=8',
660 661 :class => '' }
661 662 assert_tag :tag => 'a', :content => 'Dave Lopper',
662 663 :attributes => { :href => '/issues/bulk_edit?assigned_to_id=3&amp;ids%5B%5D=1',
663 664 :class => '' }
664 665 assert_tag :tag => 'a', :content => 'Copy',
665 666 :attributes => { :href => '/projects/ecookbook/issues/new?copy_from=1',
666 667 :class => 'icon-copy' }
667 668 assert_tag :tag => 'a', :content => 'Move',
668 669 :attributes => { :href => '/issues/move?ids%5B%5D=1',
669 670 :class => 'icon-move' }
670 671 assert_tag :tag => 'a', :content => 'Delete',
671 672 :attributes => { :href => '/issues/destroy?ids%5B%5D=1',
672 673 :class => 'icon-del' }
673 674 end
674 675
675 676 def test_context_menu_one_issue_by_anonymous
676 677 get :context_menu, :ids => [1]
677 678 assert_response :success
678 679 assert_template 'context_menu'
679 680 assert_tag :tag => 'a', :content => 'Delete',
680 681 :attributes => { :href => '#',
681 682 :class => 'icon-del disabled' }
682 683 end
683 684
684 685 def test_context_menu_multiple_issues_of_same_project
685 686 @request.session[:user_id] = 2
686 687 get :context_menu, :ids => [1, 2]
687 688 assert_response :success
688 689 assert_template 'context_menu'
689 690 assert_tag :tag => 'a', :content => 'Edit',
690 691 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;ids%5B%5D=2',
691 692 :class => 'icon-edit' }
692 693 assert_tag :tag => 'a', :content => 'Immediate',
693 694 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;ids%5B%5D=2&amp;priority_id=8',
694 695 :class => '' }
695 696 assert_tag :tag => 'a', :content => 'Dave Lopper',
696 697 :attributes => { :href => '/issues/bulk_edit?assigned_to_id=3&amp;ids%5B%5D=1&amp;ids%5B%5D=2',
697 698 :class => '' }
698 699 assert_tag :tag => 'a', :content => 'Move',
699 700 :attributes => { :href => '/issues/move?ids%5B%5D=1&amp;ids%5B%5D=2',
700 701 :class => 'icon-move' }
701 702 assert_tag :tag => 'a', :content => 'Delete',
702 703 :attributes => { :href => '/issues/destroy?ids%5B%5D=1&amp;ids%5B%5D=2',
703 704 :class => 'icon-del' }
704 705 end
705 706
706 707 def test_context_menu_multiple_issues_of_different_project
707 708 @request.session[:user_id] = 2
708 709 get :context_menu, :ids => [1, 2, 4]
709 710 assert_response :success
710 711 assert_template 'context_menu'
711 712 assert_tag :tag => 'a', :content => 'Delete',
712 713 :attributes => { :href => '#',
713 714 :class => 'icon-del disabled' }
714 715 end
715 716
716 717 def test_destroy_issue_with_no_time_entries
717 718 assert_nil TimeEntry.find_by_issue_id(2)
718 719 @request.session[:user_id] = 2
719 720 post :destroy, :id => 2
720 721 assert_redirected_to 'projects/ecookbook/issues'
721 722 assert_nil Issue.find_by_id(2)
722 723 end
723 724
724 725 def test_destroy_issues_with_time_entries
725 726 @request.session[:user_id] = 2
726 727 post :destroy, :ids => [1, 3]
727 728 assert_response :success
728 729 assert_template 'destroy'
729 730 assert_not_nil assigns(:hours)
730 731 assert Issue.find_by_id(1) && Issue.find_by_id(3)
731 732 end
732 733
733 734 def test_destroy_issues_and_destroy_time_entries
734 735 @request.session[:user_id] = 2
735 736 post :destroy, :ids => [1, 3], :todo => 'destroy'
736 737 assert_redirected_to 'projects/ecookbook/issues'
737 738 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
738 739 assert_nil TimeEntry.find_by_id([1, 2])
739 740 end
740 741
741 742 def test_destroy_issues_and_assign_time_entries_to_project
742 743 @request.session[:user_id] = 2
743 744 post :destroy, :ids => [1, 3], :todo => 'nullify'
744 745 assert_redirected_to 'projects/ecookbook/issues'
745 746 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
746 747 assert_nil TimeEntry.find(1).issue_id
747 748 assert_nil TimeEntry.find(2).issue_id
748 749 end
749 750
750 751 def test_destroy_issues_and_reassign_time_entries_to_another_issue
751 752 @request.session[:user_id] = 2
752 753 post :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
753 754 assert_redirected_to 'projects/ecookbook/issues'
754 755 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
755 756 assert_equal 2, TimeEntry.find(1).issue_id
756 757 assert_equal 2, TimeEntry.find(2).issue_id
757 758 end
758 759 end
@@ -1,278 +1,278
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 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.dirname(__FILE__) + '/../test_helper'
19 19 require 'timelog_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class TimelogController; def rescue_action(e) raise e end; end
23 23
24 24 class TimelogControllerTest < Test::Unit::TestCase
25 25 fixtures :projects, :enabled_modules, :roles, :members, :issues, :time_entries, :users, :trackers, :enumerations, :issue_statuses, :custom_fields, :custom_values
26 26
27 27 def setup
28 28 @controller = TimelogController.new
29 29 @request = ActionController::TestRequest.new
30 30 @response = ActionController::TestResponse.new
31 31 end
32 32
33 33 def test_get_edit
34 34 @request.session[:user_id] = 3
35 35 get :edit, :project_id => 1
36 36 assert_response :success
37 37 assert_template 'edit'
38 38 # Default activity selected
39 39 assert_tag :tag => 'option', :attributes => { :selected => 'selected' },
40 40 :content => 'Development'
41 41 end
42 42
43 43 def test_post_edit
44 44 @request.session[:user_id] = 3
45 45 post :edit, :project_id => 1,
46 46 :time_entry => {:comments => 'Some work on TimelogControllerTest',
47 47 # Not the default activity
48 48 :activity_id => '11',
49 49 :spent_on => '2008-03-14',
50 50 :issue_id => '1',
51 51 :hours => '7.3'}
52 52 assert_redirected_to 'projects/ecookbook/timelog/details'
53 53
54 54 i = Issue.find(1)
55 55 t = TimeEntry.find_by_comments('Some work on TimelogControllerTest')
56 56 assert_not_nil t
57 57 assert_equal 11, t.activity_id
58 58 assert_equal 7.3, t.hours
59 59 assert_equal 3, t.user_id
60 60 assert_equal i, t.issue
61 61 assert_equal i.project, t.project
62 62 end
63 63
64 64 def test_update
65 65 entry = TimeEntry.find(1)
66 66 assert_equal 1, entry.issue_id
67 67 assert_equal 2, entry.user_id
68 68
69 69 @request.session[:user_id] = 1
70 70 post :edit, :id => 1,
71 71 :time_entry => {:issue_id => '2',
72 72 :hours => '8'}
73 73 assert_redirected_to 'projects/ecookbook/timelog/details'
74 74 entry.reload
75 75
76 76 assert_equal 8, entry.hours
77 77 assert_equal 2, entry.issue_id
78 78 assert_equal 2, entry.user_id
79 79 end
80 80
81 81 def test_destroy
82 82 @request.session[:user_id] = 2
83 83 post :destroy, :id => 1
84 84 assert_redirected_to 'projects/ecookbook/timelog/details'
85 85 assert_nil TimeEntry.find_by_id(1)
86 86 end
87 87
88 88 def test_report_no_criteria
89 89 get :report, :project_id => 1
90 90 assert_response :success
91 91 assert_template 'report'
92 92 end
93 93
94 94 def test_report_all_projects
95 95 get :report
96 96 assert_response :success
97 97 assert_template 'report'
98 98 end
99 99
100 100 def test_report_all_projects_denied
101 101 r = Role.anonymous
102 102 r.permissions.delete(:view_time_entries)
103 103 r.permissions_will_change!
104 104 r.save
105 105 get :report
106 assert_redirected_to '/account/login'
106 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Ftimelog%2Freport'
107 107 end
108 108
109 109 def test_report_all_projects_one_criteria
110 110 get :report, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criterias => ['project']
111 111 assert_response :success
112 112 assert_template 'report'
113 113 assert_not_nil assigns(:total_hours)
114 114 assert_equal "8.65", "%.2f" % assigns(:total_hours)
115 115 end
116 116
117 117 def test_report_all_time
118 118 get :report, :project_id => 1, :criterias => ['project', 'issue']
119 119 assert_response :success
120 120 assert_template 'report'
121 121 assert_not_nil assigns(:total_hours)
122 122 assert_equal "162.90", "%.2f" % assigns(:total_hours)
123 123 end
124 124
125 125 def test_report_all_time_by_day
126 126 get :report, :project_id => 1, :criterias => ['project', 'issue'], :columns => 'day'
127 127 assert_response :success
128 128 assert_template 'report'
129 129 assert_not_nil assigns(:total_hours)
130 130 assert_equal "162.90", "%.2f" % assigns(:total_hours)
131 131 assert_tag :tag => 'th', :content => '2007-03-12'
132 132 end
133 133
134 134 def test_report_one_criteria
135 135 get :report, :project_id => 1, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criterias => ['project']
136 136 assert_response :success
137 137 assert_template 'report'
138 138 assert_not_nil assigns(:total_hours)
139 139 assert_equal "8.65", "%.2f" % assigns(:total_hours)
140 140 end
141 141
142 142 def test_report_two_criterias
143 143 get :report, :project_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criterias => ["member", "activity"]
144 144 assert_response :success
145 145 assert_template 'report'
146 146 assert_not_nil assigns(:total_hours)
147 147 assert_equal "162.90", "%.2f" % assigns(:total_hours)
148 148 end
149 149
150 150 def test_report_custom_field_criteria
151 151 get :report, :project_id => 1, :criterias => ['project', 'cf_1']
152 152 assert_response :success
153 153 assert_template 'report'
154 154 assert_not_nil assigns(:total_hours)
155 155 assert_not_nil assigns(:criterias)
156 156 assert_equal 2, assigns(:criterias).size
157 157 assert_equal "162.90", "%.2f" % assigns(:total_hours)
158 158 # Custom field column
159 159 assert_tag :tag => 'th', :content => 'Database'
160 160 # Custom field row
161 161 assert_tag :tag => 'td', :content => 'MySQL',
162 162 :sibling => { :tag => 'td', :attributes => { :class => 'hours' },
163 163 :child => { :tag => 'span', :attributes => { :class => 'hours hours-int' },
164 164 :content => '1' }}
165 165 end
166 166
167 167 def test_report_one_criteria_no_result
168 168 get :report, :project_id => 1, :columns => 'week', :from => "1998-04-01", :to => "1998-04-30", :criterias => ['project']
169 169 assert_response :success
170 170 assert_template 'report'
171 171 assert_not_nil assigns(:total_hours)
172 172 assert_equal "0.00", "%.2f" % assigns(:total_hours)
173 173 end
174 174
175 175 def test_report_all_projects_csv_export
176 176 get :report, :columns => 'month', :from => "2007-01-01", :to => "2007-06-30", :criterias => ["project", "member", "activity"], :format => "csv"
177 177 assert_response :success
178 178 assert_equal 'text/csv', @response.content_type
179 179 lines = @response.body.chomp.split("\n")
180 180 # Headers
181 181 assert_equal 'Project,Member,Activity,2007-1,2007-2,2007-3,2007-4,2007-5,2007-6,Total', lines.first
182 182 # Total row
183 183 assert_equal 'Total,"","","","",154.25,8.65,"","",162.90', lines.last
184 184 end
185 185
186 186 def test_report_csv_export
187 187 get :report, :project_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-06-30", :criterias => ["project", "member", "activity"], :format => "csv"
188 188 assert_response :success
189 189 assert_equal 'text/csv', @response.content_type
190 190 lines = @response.body.chomp.split("\n")
191 191 # Headers
192 192 assert_equal 'Project,Member,Activity,2007-1,2007-2,2007-3,2007-4,2007-5,2007-6,Total', lines.first
193 193 # Total row
194 194 assert_equal 'Total,"","","","",154.25,8.65,"","",162.90', lines.last
195 195 end
196 196
197 197 def test_details_all_projects
198 198 get :details
199 199 assert_response :success
200 200 assert_template 'details'
201 201 assert_not_nil assigns(:total_hours)
202 202 assert_equal "162.90", "%.2f" % assigns(:total_hours)
203 203 end
204 204
205 205 def test_details_at_project_level
206 206 get :details, :project_id => 1
207 207 assert_response :success
208 208 assert_template 'details'
209 209 assert_not_nil assigns(:entries)
210 210 assert_equal 4, assigns(:entries).size
211 211 # project and subproject
212 212 assert_equal [1, 3], assigns(:entries).collect(&:project_id).uniq.sort
213 213 assert_not_nil assigns(:total_hours)
214 214 assert_equal "162.90", "%.2f" % assigns(:total_hours)
215 215 # display all time by default
216 216 assert_equal '2007-03-11'.to_date, assigns(:from)
217 217 assert_equal '2007-04-22'.to_date, assigns(:to)
218 218 end
219 219
220 220 def test_details_at_project_level_with_date_range
221 221 get :details, :project_id => 1, :from => '2007-03-20', :to => '2007-04-30'
222 222 assert_response :success
223 223 assert_template 'details'
224 224 assert_not_nil assigns(:entries)
225 225 assert_equal 3, assigns(:entries).size
226 226 assert_not_nil assigns(:total_hours)
227 227 assert_equal "12.90", "%.2f" % assigns(:total_hours)
228 228 assert_equal '2007-03-20'.to_date, assigns(:from)
229 229 assert_equal '2007-04-30'.to_date, assigns(:to)
230 230 end
231 231
232 232 def test_details_at_project_level_with_period
233 233 get :details, :project_id => 1, :period => '7_days'
234 234 assert_response :success
235 235 assert_template 'details'
236 236 assert_not_nil assigns(:entries)
237 237 assert_not_nil assigns(:total_hours)
238 238 assert_equal Date.today - 7, assigns(:from)
239 239 assert_equal Date.today, assigns(:to)
240 240 end
241 241
242 242 def test_details_at_issue_level
243 243 get :details, :issue_id => 1
244 244 assert_response :success
245 245 assert_template 'details'
246 246 assert_not_nil assigns(:entries)
247 247 assert_equal 2, assigns(:entries).size
248 248 assert_not_nil assigns(:total_hours)
249 249 assert_equal 154.25, assigns(:total_hours)
250 250 # display all time by default
251 251 assert_equal '2007-03-11'.to_date, assigns(:from)
252 252 assert_equal '2007-04-22'.to_date, assigns(:to)
253 253 end
254 254
255 255 def test_details_atom_feed
256 256 get :details, :project_id => 1, :format => 'atom'
257 257 assert_response :success
258 258 assert_equal 'application/atom+xml', @response.content_type
259 259 assert_not_nil assigns(:items)
260 260 assert assigns(:items).first.is_a?(TimeEntry)
261 261 end
262 262
263 263 def test_details_all_projects_csv_export
264 264 get :details, :format => 'csv'
265 265 assert_response :success
266 266 assert_equal 'text/csv', @response.content_type
267 267 assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment\n")
268 268 assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\"\n")
269 269 end
270 270
271 271 def test_details_csv_export
272 272 get :details, :project_id => 1, :format => 'csv'
273 273 assert_response :success
274 274 assert_equal 'text/csv', @response.content_type
275 275 assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment\n")
276 276 assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\"\n")
277 277 end
278 278 end
@@ -1,72 +1,72
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 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.dirname(__FILE__) + '/../test_helper'
19 19 require 'users_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class UsersController; def rescue_action(e) raise e end; end
23 23
24 24 class UsersControllerTest < Test::Unit::TestCase
25 25 fixtures :users, :projects, :members
26 26
27 27 def setup
28 28 @controller = UsersController.new
29 29 @request = ActionController::TestRequest.new
30 30 @response = ActionController::TestResponse.new
31 31 User.current = nil
32 32 @request.session[:user_id] = 1 # admin
33 33 end
34 34
35 35 def test_index
36 36 get :index
37 37 assert_response :success
38 38 assert_template 'list'
39 39 end
40 40
41 41 def test_list
42 42 get :list
43 43 assert_response :success
44 44 assert_template 'list'
45 45 assert_not_nil assigns(:users)
46 46 # active users only
47 47 assert_nil assigns(:users).detect {|u| !u.active?}
48 48 end
49 49
50 50 def test_list_with_name_filter
51 51 get :list, :name => 'john'
52 52 assert_response :success
53 53 assert_template 'list'
54 54 users = assigns(:users)
55 55 assert_not_nil users
56 56 assert_equal 1, users.size
57 57 assert_equal 'John', users.first.firstname
58 58 end
59 59
60 60 def test_edit_membership
61 61 post :edit_membership, :id => 2, :membership_id => 1,
62 62 :membership => { :role_id => 2}
63 assert_redirected_to 'users/edit/2'
63 assert_redirected_to '/users/edit/2?tab=memberships'
64 64 assert_equal 2, Member.find(1).role_id
65 65 end
66 66
67 67 def test_destroy_membership
68 68 post :destroy_membership, :id => 2, :membership_id => 1
69 assert_redirected_to 'users/edit/2'
69 assert_redirected_to '/users/edit/2?tab=memberships'
70 70 assert_nil Member.find_by_id(1)
71 71 end
72 72 end
@@ -1,73 +1,73
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 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.dirname(__FILE__) + '/../test_helper'
19 19 require 'versions_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class VersionsController; def rescue_action(e) raise e end; end
23 23
24 24 class VersionsControllerTest < Test::Unit::TestCase
25 25 fixtures :projects, :versions, :issues, :users, :roles, :members, :enabled_modules
26 26
27 27 def setup
28 28 @controller = VersionsController.new
29 29 @request = ActionController::TestRequest.new
30 30 @response = ActionController::TestResponse.new
31 31 User.current = nil
32 32 end
33 33
34 34 def test_show
35 35 get :show, :id => 2
36 36 assert_response :success
37 37 assert_template 'show'
38 38 assert_not_nil assigns(:version)
39 39
40 40 assert_tag :tag => 'h2', :content => /1.0/
41 41 end
42 42
43 43 def test_get_edit
44 44 @request.session[:user_id] = 2
45 45 get :edit, :id => 2
46 46 assert_response :success
47 47 assert_template 'edit'
48 48 end
49 49
50 50 def test_post_edit
51 51 @request.session[:user_id] = 2
52 52 post :edit, :id => 2,
53 53 :version => { :name => 'New version name',
54 54 :effective_date => Date.today.strftime("%Y-%m-%d")}
55 assert_redirected_to 'projects/settings/ecookbook'
55 assert_redirected_to '/projects/settings/ecookbook?tab=versions'
56 56 version = Version.find(2)
57 57 assert_equal 'New version name', version.name
58 58 assert_equal Date.today, version.effective_date
59 59 end
60 60
61 61 def test_destroy
62 62 @request.session[:user_id] = 2
63 63 post :destroy, :id => 3
64 assert_redirected_to 'projects/settings/ecookbook'
64 assert_redirected_to '/projects/settings/ecookbook?tab=versions'
65 65 assert_nil Version.find_by_id(3)
66 66 end
67 67
68 68 def test_issue_status_by
69 69 xhr :get, :status_by, :id => 2
70 70 assert_response :success
71 71 assert_template '_issue_counts'
72 72 end
73 73 end
@@ -1,259 +1,259
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 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.dirname(__FILE__) + '/../test_helper'
19 19 require 'wiki_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class WikiController; def rescue_action(e) raise e end; end
23 23
24 24 class WikiControllerTest < Test::Unit::TestCase
25 25 fixtures :projects, :users, :roles, :members, :enabled_modules, :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions, :attachments
26 26
27 27 def setup
28 28 @controller = WikiController.new
29 29 @request = ActionController::TestRequest.new
30 30 @response = ActionController::TestResponse.new
31 31 User.current = nil
32 32 end
33 33
34 34 def test_show_start_page
35 35 get :index, :id => 'ecookbook'
36 36 assert_response :success
37 37 assert_template 'show'
38 38 assert_tag :tag => 'h1', :content => /CookBook documentation/
39 39
40 40 # child_pages macro
41 41 assert_tag :ul, :attributes => { :class => 'pages-hierarchy' },
42 42 :child => { :tag => 'li',
43 43 :child => { :tag => 'a', :attributes => { :href => '/wiki/ecookbook/Page_with_an_inline_image' },
44 44 :content => 'Page with an inline image' } }
45 45 end
46 46
47 47 def test_show_page_with_name
48 48 get :index, :id => 1, :page => 'Another_page'
49 49 assert_response :success
50 50 assert_template 'show'
51 51 assert_tag :tag => 'h1', :content => /Another page/
52 52 # Included page with an inline image
53 53 assert_tag :tag => 'p', :content => /This is an inline image/
54 54 assert_tag :tag => 'img', :attributes => { :src => '/attachments/download/3',
55 55 :alt => 'This is a logo' }
56 56 end
57 57
58 58 def test_show_unexistent_page_without_edit_right
59 59 get :index, :id => 1, :page => 'Unexistent page'
60 60 assert_response 404
61 61 end
62 62
63 63 def test_show_unexistent_page_with_edit_right
64 64 @request.session[:user_id] = 2
65 65 get :index, :id => 1, :page => 'Unexistent page'
66 66 assert_response :success
67 67 assert_template 'edit'
68 68 end
69 69
70 70 def test_create_page
71 71 @request.session[:user_id] = 2
72 72 post :edit, :id => 1,
73 73 :page => 'New page',
74 74 :content => {:comments => 'Created the page',
75 75 :text => "h1. New page\n\nThis is a new page",
76 76 :version => 0}
77 77 assert_redirected_to 'wiki/ecookbook/New_page'
78 78 page = Project.find(1).wiki.find_page('New page')
79 79 assert !page.new_record?
80 80 assert_not_nil page.content
81 81 assert_equal 'Created the page', page.content.comments
82 82 end
83 83
84 84 def test_preview
85 85 @request.session[:user_id] = 2
86 86 xhr :post, :preview, :id => 1, :page => 'CookBook_documentation',
87 87 :content => { :comments => '',
88 88 :text => 'this is a *previewed text*',
89 89 :version => 3 }
90 90 assert_response :success
91 91 assert_template 'common/_preview'
92 92 assert_tag :tag => 'strong', :content => /previewed text/
93 93 end
94 94
95 95 def test_preview_new_page
96 96 @request.session[:user_id] = 2
97 97 xhr :post, :preview, :id => 1, :page => 'New page',
98 98 :content => { :text => 'h1. New page',
99 99 :comments => '',
100 100 :version => 0 }
101 101 assert_response :success
102 102 assert_template 'common/_preview'
103 103 assert_tag :tag => 'h1', :content => /New page/
104 104 end
105 105
106 106 def test_history
107 107 get :history, :id => 1, :page => 'CookBook_documentation'
108 108 assert_response :success
109 109 assert_template 'history'
110 110 assert_not_nil assigns(:versions)
111 111 assert_equal 3, assigns(:versions).size
112 112 assert_select "input[type=submit][name=commit]"
113 113 end
114 114
115 115 def test_history_with_one_version
116 116 get :history, :id => 1, :page => 'Another_page'
117 117 assert_response :success
118 118 assert_template 'history'
119 119 assert_not_nil assigns(:versions)
120 120 assert_equal 1, assigns(:versions).size
121 121 assert_select "input[type=submit][name=commit]", false
122 122 end
123 123
124 124 def test_diff
125 125 get :diff, :id => 1, :page => 'CookBook_documentation', :version => 2, :version_from => 1
126 126 assert_response :success
127 127 assert_template 'diff'
128 128 assert_tag :tag => 'span', :attributes => { :class => 'diff_in'},
129 129 :content => /updated/
130 130 end
131 131
132 132 def test_annotate
133 133 get :annotate, :id => 1, :page => 'CookBook_documentation', :version => 2
134 134 assert_response :success
135 135 assert_template 'annotate'
136 136 # Line 1
137 137 assert_tag :tag => 'tr', :child => { :tag => 'th', :attributes => {:class => 'line-num'}, :content => '1' },
138 138 :child => { :tag => 'td', :attributes => {:class => 'author'}, :content => /John Smith/ },
139 139 :child => { :tag => 'td', :content => /h1\. CookBook documentation/ }
140 140 # Line 2
141 141 assert_tag :tag => 'tr', :child => { :tag => 'th', :attributes => {:class => 'line-num'}, :content => '2' },
142 142 :child => { :tag => 'td', :attributes => {:class => 'author'}, :content => /redMine Admin/ },
143 143 :child => { :tag => 'td', :content => /Some updated \[\[documentation\]\] here/ }
144 144 end
145 145
146 146 def test_rename_with_redirect
147 147 @request.session[:user_id] = 2
148 148 post :rename, :id => 1, :page => 'Another_page',
149 149 :wiki_page => { :title => 'Another renamed page',
150 150 :redirect_existing_links => 1 }
151 151 assert_redirected_to 'wiki/ecookbook/Another_renamed_page'
152 152 wiki = Project.find(1).wiki
153 153 # Check redirects
154 154 assert_not_nil wiki.find_page('Another page')
155 155 assert_nil wiki.find_page('Another page', :with_redirect => false)
156 156 end
157 157
158 158 def test_rename_without_redirect
159 159 @request.session[:user_id] = 2
160 160 post :rename, :id => 1, :page => 'Another_page',
161 161 :wiki_page => { :title => 'Another renamed page',
162 162 :redirect_existing_links => "0" }
163 163 assert_redirected_to 'wiki/ecookbook/Another_renamed_page'
164 164 wiki = Project.find(1).wiki
165 165 # Check that there's no redirects
166 166 assert_nil wiki.find_page('Another page')
167 167 end
168 168
169 169 def test_destroy
170 170 @request.session[:user_id] = 2
171 171 post :destroy, :id => 1, :page => 'CookBook_documentation'
172 172 assert_redirected_to 'wiki/ecookbook/Page_index/special'
173 173 end
174 174
175 175 def test_page_index
176 176 get :special, :id => 'ecookbook', :page => 'Page_index'
177 177 assert_response :success
178 178 assert_template 'special_page_index'
179 179 pages = assigns(:pages)
180 180 assert_not_nil pages
181 181 assert_equal Project.find(1).wiki.pages.size, pages.size
182 182
183 183 assert_tag :ul, :attributes => { :class => 'pages-hierarchy' },
184 184 :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/wiki/ecookbook/CookBook_documentation' },
185 185 :content => 'CookBook documentation' },
186 186 :child => { :tag => 'ul',
187 187 :child => { :tag => 'li',
188 188 :child => { :tag => 'a', :attributes => { :href => '/wiki/ecookbook/Page_with_an_inline_image' },
189 189 :content => 'Page with an inline image' } } } },
190 190 :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/wiki/ecookbook/Another_page' },
191 191 :content => 'Another page' } }
192 192 end
193 193
194 194 def test_not_found
195 195 get :index, :id => 999
196 196 assert_response 404
197 197 end
198 198
199 199 def test_protect_page
200 200 page = WikiPage.find_by_wiki_id_and_title(1, 'Another_page')
201 201 assert !page.protected?
202 202 @request.session[:user_id] = 2
203 203 post :protect, :id => 1, :page => page.title, :protected => '1'
204 204 assert_redirected_to 'wiki/ecookbook/Another_page'
205 205 assert page.reload.protected?
206 206 end
207 207
208 208 def test_unprotect_page
209 209 page = WikiPage.find_by_wiki_id_and_title(1, 'CookBook_documentation')
210 210 assert page.protected?
211 211 @request.session[:user_id] = 2
212 212 post :protect, :id => 1, :page => page.title, :protected => '0'
213 assert_redirected_to 'wiki/ecookbook'
213 assert_redirected_to '/wiki/ecookbook/CookBook_documentation'
214 214 assert !page.reload.protected?
215 215 end
216 216
217 217 def test_show_page_with_edit_link
218 218 @request.session[:user_id] = 2
219 219 get :index, :id => 1
220 220 assert_response :success
221 221 assert_template 'show'
222 222 assert_tag :tag => 'a', :attributes => { :href => '/wiki/1/CookBook_documentation/edit' }
223 223 end
224 224
225 225 def test_show_page_without_edit_link
226 226 @request.session[:user_id] = 4
227 227 get :index, :id => 1
228 228 assert_response :success
229 229 assert_template 'show'
230 230 assert_no_tag :tag => 'a', :attributes => { :href => '/wiki/1/CookBook_documentation/edit' }
231 231 end
232 232
233 233 def test_edit_unprotected_page
234 234 # Non members can edit unprotected wiki pages
235 235 @request.session[:user_id] = 4
236 236 get :edit, :id => 1, :page => 'Another_page'
237 237 assert_response :success
238 238 assert_template 'edit'
239 239 end
240 240
241 241 def test_edit_protected_page_by_nonmember
242 242 # Non members can't edit protected wiki pages
243 243 @request.session[:user_id] = 4
244 244 get :edit, :id => 1, :page => 'CookBook_documentation'
245 245 assert_response 403
246 246 end
247 247
248 248 def test_edit_protected_page_by_member
249 249 @request.session[:user_id] = 2
250 250 get :edit, :id => 1, :page => 'CookBook_documentation'
251 251 assert_response :success
252 252 assert_template 'edit'
253 253 end
254 254
255 255 def test_history_of_non_existing_page_should_return_404
256 256 get :history, :id => 1, :page => 'Unknown_page'
257 257 assert_response 404
258 258 end
259 259 end
@@ -1,56 +1,56
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 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.dirname(__FILE__) + '/../test_helper'
19 19 require 'wikis_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class WikisController; def rescue_action(e) raise e end; end
23 23
24 24 class WikisControllerTest < Test::Unit::TestCase
25 25 fixtures :projects, :users, :roles, :members, :enabled_modules, :wikis
26 26
27 27 def setup
28 28 @controller = WikisController.new
29 29 @request = ActionController::TestRequest.new
30 30 @response = ActionController::TestResponse.new
31 31 User.current = nil
32 32 end
33 33
34 34 def test_create
35 35 @request.session[:user_id] = 1
36 36 assert_nil Project.find(3).wiki
37 37 post :edit, :id => 3, :wiki => { :start_page => 'Start page' }
38 38 assert_response :success
39 39 wiki = Project.find(3).wiki
40 40 assert_not_nil wiki
41 41 assert_equal 'Start page', wiki.start_page
42 42 end
43 43
44 44 def test_destroy
45 45 @request.session[:user_id] = 1
46 46 post :destroy, :id => 1, :confirm => 1
47 assert_redirected_to 'projects/settings/ecookbook'
47 assert_redirected_to '/projects/settings/ecookbook?tab=wiki'
48 48 assert_nil Project.find(1).wiki
49 49 end
50 50
51 51 def test_not_found
52 52 @request.session[:user_id] = 1
53 53 post :destroy, :id => 999, :confirm => 1
54 54 assert_response 404
55 55 end
56 56 end
@@ -1,84 +1,84
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2008 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.dirname(__FILE__) + '/../test_helper'
19 19 require 'workflows_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class WorkflowsController; def rescue_action(e) raise e end; end
23 23
24 24 class WorkflowsControllerTest < Test::Unit::TestCase
25 25 fixtures :roles, :trackers, :workflows
26 26
27 27 def setup
28 28 @controller = WorkflowsController.new
29 29 @request = ActionController::TestRequest.new
30 30 @response = ActionController::TestResponse.new
31 31 User.current = nil
32 32 @request.session[:user_id] = 1 # admin
33 33 end
34 34
35 35 def test_index
36 36 get :index
37 37 assert_response :success
38 38 assert_template 'index'
39 39
40 40 count = Workflow.count(:all, :conditions => 'role_id = 1 AND tracker_id = 2')
41 41 assert_tag :tag => 'a', :content => count.to_s,
42 42 :attributes => { :href => '/workflows/edit?role_id=1&amp;tracker_id=2' }
43 43 end
44 44
45 45 def test_get_edit
46 46 get :edit
47 47 assert_response :success
48 48 assert_template 'edit'
49 49 assert_not_nil assigns(:roles)
50 50 assert_not_nil assigns(:trackers)
51 51 end
52 52
53 53 def test_get_edit_with_role_and_tracker
54 54 get :edit, :role_id => 2, :tracker_id => 1
55 55 assert_response :success
56 56 assert_template 'edit'
57 57 # allowed transitions
58 58 assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
59 59 :name => 'issue_status[2][]',
60 60 :value => '1',
61 61 :checked => 'checked' }
62 62 # not allowed
63 63 assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
64 64 :name => 'issue_status[2][]',
65 65 :value => '3',
66 66 :checked => nil }
67 67 end
68 68
69 69 def test_post_edit
70 70 post :edit, :role_id => 2, :tracker_id => 1, :issue_status => {'4' => ['5'], '3' => ['1', '2']}
71 assert_redirected_to 'workflows/edit'
71 assert_redirected_to '/workflows/edit?role_id=2&tracker_id=1'
72 72
73 73 assert_equal 3, Workflow.count(:conditions => {:tracker_id => 1, :role_id => 2})
74 74 assert_not_nil Workflow.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 2})
75 75 assert_nil Workflow.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 5, :new_status_id => 4})
76 76 end
77 77
78 78 def test_clear_workflow
79 79 assert Workflow.count(:conditions => {:tracker_id => 1, :role_id => 2}) > 0
80 80
81 81 post :edit, :role_id => 2, :tracker_id => 1
82 82 assert_equal 0, Workflow.count(:conditions => {:tracker_id => 1, :role_id => 2})
83 83 end
84 84 end
General Comments 0
You need to be logged in to leave comments. Login now