##// END OF EJS Templates
Don't show the project dropdown when logging time on an issue....
Jean-Philippe Lang -
r10000:e06bf0c46418
parent child
Show More
@@ -1,23 +1,23
1 1 <%= error_messages_for 'time_entry' %>
2 2 <%= back_url_hidden_field_tag %>
3 3
4 4 <div class="box tabular">
5 5 <% if @time_entry.new_record? %>
6 <% if params[:project_id] %>
6 <% if params[:project_id] || @time_entry.issue %>
7 7 <%= f.hidden_field :project_id %>
8 8 <% else %>
9 9 <p><%= f.select :project_id, project_tree_options_for_select(Project.allowed_to(:log_time).all, :selected => @time_entry.project), :required => true %></p>
10 10 <% end %>
11 11 <% end %>
12 12 <p><%= f.text_field :issue_id, :size => 6 %> <em><%= h("#{@time_entry.issue.tracker.name} ##{@time_entry.issue.id}: #{@time_entry.issue.subject}") if @time_entry.issue %></em></p>
13 13 <p><%= f.text_field :spent_on, :size => 10, :required => true %><%= calendar_for('time_entry_spent_on') %></p>
14 14 <p><%= f.text_field :hours, :size => 6, :required => true %></p>
15 15 <p><%= f.text_field :comments, :size => 100 %></p>
16 16 <p><%= f.select :activity_id, activity_collection_for_select_options(@time_entry), :required => true %></p>
17 17 <% @time_entry.custom_field_values.each do |value| %>
18 18 <p><%= custom_field_tag_with_label :time_entry, value %></p>
19 19 <% end %>
20 20 <%= call_hook(:view_timelog_edit_form_bottom, { :time_entry => @time_entry, :form => f }) %>
21 21 </div>
22 22
23 23 <%= javascript_tag "observeAutocompleteField('time_entry_issue_id', '#{escape_javascript auto_complete_issues_path(:project_id => @project, :scope => (@project ? nil : 'all'))}')" %>
@@ -1,775 +1,789
1 1 # -*- coding: utf-8 -*-
2 2 # Redmine - project management software
3 3 # Copyright (C) 2006-2012 Jean-Philippe Lang
4 4 #
5 5 # This program is free software; you can redistribute it and/or
6 6 # modify it under the terms of the GNU General Public License
7 7 # as published by the Free Software Foundation; either version 2
8 8 # of the License, or (at your option) any later version.
9 9 #
10 10 # This program is distributed in the hope that it will be useful,
11 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 # GNU General Public License for more details.
14 14 #
15 15 # You should have received a copy of the GNU General Public License
16 16 # along with this program; if not, write to the Free Software
17 17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 18
19 19 require File.expand_path('../../test_helper', __FILE__)
20 20 require 'timelog_controller'
21 21
22 22 # Re-raise errors caught by the controller.
23 23 class TimelogController; def rescue_action(e) raise e end; end
24 24
25 25 class TimelogControllerTest < ActionController::TestCase
26 26 fixtures :projects, :enabled_modules, :roles, :members,
27 27 :member_roles, :issues, :time_entries, :users,
28 28 :trackers, :enumerations, :issue_statuses,
29 29 :custom_fields, :custom_values
30 30
31 31 include Redmine::I18n
32 32
33 33 def setup
34 34 @controller = TimelogController.new
35 35 @request = ActionController::TestRequest.new
36 36 @response = ActionController::TestResponse.new
37 37 end
38 38
39 def test_get_new
39 def test_new_with_project_id
40 40 @request.session[:user_id] = 3
41 41 get :new, :project_id => 1
42 42 assert_response :success
43 43 assert_template 'new'
44 # Default activity selected
45 assert_tag :tag => 'option', :attributes => { :selected => 'selected' },
46 :content => 'Development'
47 assert_select 'input[name=project_id][value=1]'
44 assert_select 'select[name=?]', 'time_entry[project_id]', 0
45 assert_select 'input[name=?][value=1][type=hidden]', 'time_entry[project_id]'
48 46 end
49 47
50 def test_get_new_should_only_show_active_time_entry_activities
48 def test_new_with_issue_id
51 49 @request.session[:user_id] = 3
52 get :new, :project_id => 1
50 get :new, :issue_id => 2
53 51 assert_response :success
54 52 assert_template 'new'
55 assert_no_tag 'select', :attributes => {:name => 'time_entry[project_id]'}
56 assert_no_tag 'option', :content => 'Inactive Activity'
53 assert_select 'select[name=?]', 'time_entry[project_id]', 0
54 assert_select 'input[name=?][value=1][type=hidden]', 'time_entry[project_id]'
57 55 end
58 56
59 57 def test_new_without_project
60 58 @request.session[:user_id] = 3
61 59 get :new
62 60 assert_response :success
63 61 assert_template 'new'
64 assert_tag 'select', :attributes => {:name => 'time_entry[project_id]'}
65 assert_select 'input[name=project_id]', 0
62 assert_select 'select[name=?]', 'time_entry[project_id]'
63 assert_select 'input[name=?]', 'time_entry[project_id]', 0
66 64 end
67 65
68 66 def test_new_without_project_should_prefill_the_form
69 67 @request.session[:user_id] = 3
70 68 get :new, :time_entry => {:project_id => '1'}
71 69 assert_response :success
72 70 assert_template 'new'
73 71 assert_select 'select[name=?]', 'time_entry[project_id]' do
74 72 assert_select 'option[value=1][selected=selected]'
75 73 end
76 assert_select 'input[name=project_id]', 0
74 assert_select 'input[name=?]', 'time_entry[project_id]', 0
77 75 end
78 76
79 77 def test_new_without_project_should_deny_without_permission
80 78 Role.all.each {|role| role.remove_permission! :log_time}
81 79 @request.session[:user_id] = 3
82 80
83 81 get :new
84 82 assert_response 403
85 83 end
86 84
85 def test_new_should_select_default_activity
86 @request.session[:user_id] = 3
87 get :new, :project_id => 1
88 assert_response :success
89 assert_select 'select[name=?]', 'time_entry[activity_id]' do
90 assert_select 'option[selected=selected]', :text => 'Development'
91 end
92 end
93
94 def test_new_should_only_show_active_time_entry_activities
95 @request.session[:user_id] = 3
96 get :new, :project_id => 1
97 assert_response :success
98 assert_no_tag 'option', :content => 'Inactive Activity'
99 end
100
87 101 def test_get_edit_existing_time
88 102 @request.session[:user_id] = 2
89 103 get :edit, :id => 2, :project_id => nil
90 104 assert_response :success
91 105 assert_template 'edit'
92 106 # Default activity selected
93 107 assert_tag :tag => 'form', :attributes => { :action => '/projects/ecookbook/time_entries/2' }
94 108 end
95 109
96 110 def test_get_edit_with_an_existing_time_entry_with_inactive_activity
97 111 te = TimeEntry.find(1)
98 112 te.activity = TimeEntryActivity.find_by_name("Inactive Activity")
99 113 te.save!
100 114
101 115 @request.session[:user_id] = 1
102 116 get :edit, :project_id => 1, :id => 1
103 117 assert_response :success
104 118 assert_template 'edit'
105 119 # Blank option since nothing is pre-selected
106 120 assert_tag :tag => 'option', :content => '--- Please select ---'
107 121 end
108 122
109 123 def test_post_create
110 124 # TODO: should POST to issues’ time log instead of project. change form
111 125 # and routing
112 126 @request.session[:user_id] = 3
113 127 post :create, :project_id => 1,
114 128 :time_entry => {:comments => 'Some work on TimelogControllerTest',
115 129 # Not the default activity
116 130 :activity_id => '11',
117 131 :spent_on => '2008-03-14',
118 132 :issue_id => '1',
119 133 :hours => '7.3'}
120 134 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
121 135
122 136 i = Issue.find(1)
123 137 t = TimeEntry.find_by_comments('Some work on TimelogControllerTest')
124 138 assert_not_nil t
125 139 assert_equal 11, t.activity_id
126 140 assert_equal 7.3, t.hours
127 141 assert_equal 3, t.user_id
128 142 assert_equal i, t.issue
129 143 assert_equal i.project, t.project
130 144 end
131 145
132 146 def test_post_create_with_blank_issue
133 147 # TODO: should POST to issues’ time log instead of project. change form
134 148 # and routing
135 149 @request.session[:user_id] = 3
136 150 post :create, :project_id => 1,
137 151 :time_entry => {:comments => 'Some work on TimelogControllerTest',
138 152 # Not the default activity
139 153 :activity_id => '11',
140 154 :issue_id => '',
141 155 :spent_on => '2008-03-14',
142 156 :hours => '7.3'}
143 157 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
144 158
145 159 t = TimeEntry.find_by_comments('Some work on TimelogControllerTest')
146 160 assert_not_nil t
147 161 assert_equal 11, t.activity_id
148 162 assert_equal 7.3, t.hours
149 163 assert_equal 3, t.user_id
150 164 end
151 165
152 166 def test_create_and_continue
153 167 @request.session[:user_id] = 2
154 168 post :create, :project_id => 1,
155 169 :time_entry => {:activity_id => '11',
156 170 :issue_id => '',
157 171 :spent_on => '2008-03-14',
158 172 :hours => '7.3'},
159 173 :continue => '1'
160 174 assert_redirected_to '/projects/ecookbook/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D='
161 175 end
162 176
163 177 def test_create_and_continue_with_issue_id
164 178 @request.session[:user_id] = 2
165 179 post :create, :project_id => 1,
166 180 :time_entry => {:activity_id => '11',
167 181 :issue_id => '1',
168 182 :spent_on => '2008-03-14',
169 183 :hours => '7.3'},
170 184 :continue => '1'
171 185 assert_redirected_to '/projects/ecookbook/issues/1/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=1'
172 186 end
173 187
174 188 def test_create_and_continue_without_project
175 189 @request.session[:user_id] = 2
176 190 post :create, :time_entry => {:project_id => '1',
177 191 :activity_id => '11',
178 192 :issue_id => '',
179 193 :spent_on => '2008-03-14',
180 194 :hours => '7.3'},
181 195 :continue => '1'
182 196
183 197 assert_redirected_to '/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=&time_entry%5Bproject_id%5D=1'
184 198 end
185 199
186 200 def test_create_without_log_time_permission_should_be_denied
187 201 @request.session[:user_id] = 2
188 202 Role.find_by_name('Manager').remove_permission! :log_time
189 203 post :create, :project_id => 1,
190 204 :time_entry => {:activity_id => '11',
191 205 :issue_id => '',
192 206 :spent_on => '2008-03-14',
193 207 :hours => '7.3'}
194 208
195 209 assert_response 403
196 210 end
197 211
198 212 def test_create_with_failure
199 213 @request.session[:user_id] = 2
200 214 post :create, :project_id => 1,
201 215 :time_entry => {:activity_id => '',
202 216 :issue_id => '',
203 217 :spent_on => '2008-03-14',
204 218 :hours => '7.3'}
205 219
206 220 assert_response :success
207 221 assert_template 'new'
208 222 end
209 223
210 224 def test_create_without_project
211 225 @request.session[:user_id] = 2
212 226 assert_difference 'TimeEntry.count' do
213 227 post :create, :time_entry => {:project_id => '1',
214 228 :activity_id => '11',
215 229 :issue_id => '',
216 230 :spent_on => '2008-03-14',
217 231 :hours => '7.3'}
218 232 end
219 233
220 234 assert_redirected_to '/projects/ecookbook/time_entries'
221 235 time_entry = TimeEntry.first(:order => 'id DESC')
222 236 assert_equal 1, time_entry.project_id
223 237 end
224 238
225 239 def test_create_without_project_should_fail_with_issue_not_inside_project
226 240 @request.session[:user_id] = 2
227 241 assert_no_difference 'TimeEntry.count' do
228 242 post :create, :time_entry => {:project_id => '1',
229 243 :activity_id => '11',
230 244 :issue_id => '5',
231 245 :spent_on => '2008-03-14',
232 246 :hours => '7.3'}
233 247 end
234 248
235 249 assert_response :success
236 250 assert assigns(:time_entry).errors[:issue_id].present?
237 251 end
238 252
239 253 def test_create_without_project_should_deny_without_permission
240 254 @request.session[:user_id] = 2
241 255 Project.find(3).disable_module!(:time_tracking)
242 256
243 257 assert_no_difference 'TimeEntry.count' do
244 258 post :create, :time_entry => {:project_id => '3',
245 259 :activity_id => '11',
246 260 :issue_id => '',
247 261 :spent_on => '2008-03-14',
248 262 :hours => '7.3'}
249 263 end
250 264
251 265 assert_response 403
252 266 end
253 267
254 268 def test_create_without_project_with_failure
255 269 @request.session[:user_id] = 2
256 270 assert_no_difference 'TimeEntry.count' do
257 271 post :create, :time_entry => {:project_id => '1',
258 272 :activity_id => '11',
259 273 :issue_id => '',
260 274 :spent_on => '2008-03-14',
261 275 :hours => ''}
262 276 end
263 277
264 278 assert_response :success
265 279 assert_tag 'select', :attributes => {:name => 'time_entry[project_id]'},
266 280 :child => {:tag => 'option', :attributes => {:value => '1', :selected => 'selected'}}
267 281 end
268 282
269 283 def test_update
270 284 entry = TimeEntry.find(1)
271 285 assert_equal 1, entry.issue_id
272 286 assert_equal 2, entry.user_id
273 287
274 288 @request.session[:user_id] = 1
275 289 put :update, :id => 1,
276 290 :time_entry => {:issue_id => '2',
277 291 :hours => '8'}
278 292 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
279 293 entry.reload
280 294
281 295 assert_equal 8, entry.hours
282 296 assert_equal 2, entry.issue_id
283 297 assert_equal 2, entry.user_id
284 298 end
285 299
286 300 def test_get_bulk_edit
287 301 @request.session[:user_id] = 2
288 302 get :bulk_edit, :ids => [1, 2]
289 303 assert_response :success
290 304 assert_template 'bulk_edit'
291 305
292 306 # System wide custom field
293 307 assert_tag :select, :attributes => {:name => 'time_entry[custom_field_values][10]'}
294 308
295 309 # Activities
296 310 assert_select 'select[name=?]', 'time_entry[activity_id]' do
297 311 assert_select 'option[value=]', :text => '(No change)'
298 312 assert_select 'option[value=9]', :text => 'Design'
299 313 end
300 314 end
301 315
302 316 def test_get_bulk_edit_on_different_projects
303 317 @request.session[:user_id] = 2
304 318 get :bulk_edit, :ids => [1, 2, 6]
305 319 assert_response :success
306 320 assert_template 'bulk_edit'
307 321 end
308 322
309 323 def test_bulk_update
310 324 @request.session[:user_id] = 2
311 325 # update time entry activity
312 326 post :bulk_update, :ids => [1, 2], :time_entry => { :activity_id => 9}
313 327
314 328 assert_response 302
315 329 # check that the issues were updated
316 330 assert_equal [9, 9], TimeEntry.find_all_by_id([1, 2]).collect {|i| i.activity_id}
317 331 end
318 332
319 333 def test_bulk_update_with_failure
320 334 @request.session[:user_id] = 2
321 335 post :bulk_update, :ids => [1, 2], :time_entry => { :hours => 'A'}
322 336
323 337 assert_response 302
324 338 assert_match /Failed to save 2 time entrie/, flash[:error]
325 339 end
326 340
327 341 def test_bulk_update_on_different_projects
328 342 @request.session[:user_id] = 2
329 343 # makes user a manager on the other project
330 344 Member.create!(:user_id => 2, :project_id => 3, :role_ids => [1])
331 345
332 346 # update time entry activity
333 347 post :bulk_update, :ids => [1, 2, 4], :time_entry => { :activity_id => 9 }
334 348
335 349 assert_response 302
336 350 # check that the issues were updated
337 351 assert_equal [9, 9, 9], TimeEntry.find_all_by_id([1, 2, 4]).collect {|i| i.activity_id}
338 352 end
339 353
340 354 def test_bulk_update_on_different_projects_without_rights
341 355 @request.session[:user_id] = 3
342 356 user = User.find(3)
343 357 action = { :controller => "timelog", :action => "bulk_update" }
344 358 assert user.allowed_to?(action, TimeEntry.find(1).project)
345 359 assert ! user.allowed_to?(action, TimeEntry.find(5).project)
346 360 post :bulk_update, :ids => [1, 5], :time_entry => { :activity_id => 9 }
347 361 assert_response 403
348 362 end
349 363
350 364 def test_bulk_update_custom_field
351 365 @request.session[:user_id] = 2
352 366 post :bulk_update, :ids => [1, 2], :time_entry => { :custom_field_values => {'10' => '0'} }
353 367
354 368 assert_response 302
355 369 assert_equal ["0", "0"], TimeEntry.find_all_by_id([1, 2]).collect {|i| i.custom_value_for(10).value}
356 370 end
357 371
358 372 def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter
359 373 @request.session[:user_id] = 2
360 374 post :bulk_update, :ids => [1,2], :back_url => '/time_entries'
361 375
362 376 assert_response :redirect
363 377 assert_redirected_to '/time_entries'
364 378 end
365 379
366 380 def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
367 381 @request.session[:user_id] = 2
368 382 post :bulk_update, :ids => [1,2], :back_url => 'http://google.com'
369 383
370 384 assert_response :redirect
371 385 assert_redirected_to :controller => 'timelog', :action => 'index', :project_id => Project.find(1).identifier
372 386 end
373 387
374 388 def test_post_bulk_update_without_edit_permission_should_be_denied
375 389 @request.session[:user_id] = 2
376 390 Role.find_by_name('Manager').remove_permission! :edit_time_entries
377 391 post :bulk_update, :ids => [1,2]
378 392
379 393 assert_response 403
380 394 end
381 395
382 396 def test_destroy
383 397 @request.session[:user_id] = 2
384 398 delete :destroy, :id => 1
385 399 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
386 400 assert_equal I18n.t(:notice_successful_delete), flash[:notice]
387 401 assert_nil TimeEntry.find_by_id(1)
388 402 end
389 403
390 404 def test_destroy_should_fail
391 405 # simulate that this fails (e.g. due to a plugin), see #5700
392 406 TimeEntry.any_instance.expects(:destroy).returns(false)
393 407
394 408 @request.session[:user_id] = 2
395 409 delete :destroy, :id => 1
396 410 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
397 411 assert_equal I18n.t(:notice_unable_delete_time_entry), flash[:error]
398 412 assert_not_nil TimeEntry.find_by_id(1)
399 413 end
400 414
401 415 def test_index_all_projects
402 416 get :index
403 417 assert_response :success
404 418 assert_template 'index'
405 419 assert_not_nil assigns(:total_hours)
406 420 assert_equal "162.90", "%.2f" % assigns(:total_hours)
407 421 assert_tag :form,
408 422 :attributes => {:action => "/time_entries", :id => 'query_form'}
409 423 end
410 424
411 425 def test_index_all_projects_should_show_log_time_link
412 426 @request.session[:user_id] = 2
413 427 get :index
414 428 assert_response :success
415 429 assert_template 'index'
416 430 assert_tag 'a', :attributes => {:href => '/time_entries/new'}, :content => /Log time/
417 431 end
418 432
419 433 def test_index_at_project_level
420 434 get :index, :project_id => 'ecookbook'
421 435 assert_response :success
422 436 assert_template 'index'
423 437 assert_not_nil assigns(:entries)
424 438 assert_equal 4, assigns(:entries).size
425 439 # project and subproject
426 440 assert_equal [1, 3], assigns(:entries).collect(&:project_id).uniq.sort
427 441 assert_not_nil assigns(:total_hours)
428 442 assert_equal "162.90", "%.2f" % assigns(:total_hours)
429 443 # display all time by default
430 444 assert_nil assigns(:from)
431 445 assert_nil assigns(:to)
432 446 assert_tag :form,
433 447 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
434 448 end
435 449
436 450 def test_index_at_project_level_with_date_range
437 451 get :index, :project_id => 'ecookbook', :from => '2007-03-20', :to => '2007-04-30'
438 452 assert_response :success
439 453 assert_template 'index'
440 454 assert_not_nil assigns(:entries)
441 455 assert_equal 3, assigns(:entries).size
442 456 assert_not_nil assigns(:total_hours)
443 457 assert_equal "12.90", "%.2f" % assigns(:total_hours)
444 458 assert_equal '2007-03-20'.to_date, assigns(:from)
445 459 assert_equal '2007-04-30'.to_date, assigns(:to)
446 460 assert_tag :form,
447 461 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
448 462 end
449 463
450 464 def test_index_at_project_level_with_period
451 465 get :index, :project_id => 'ecookbook', :period => '7_days'
452 466 assert_response :success
453 467 assert_template 'index'
454 468 assert_not_nil assigns(:entries)
455 469 assert_not_nil assigns(:total_hours)
456 470 assert_equal Date.today - 7, assigns(:from)
457 471 assert_equal Date.today, assigns(:to)
458 472 assert_tag :form,
459 473 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
460 474 end
461 475
462 476 def test_index_one_day
463 477 get :index, :project_id => 'ecookbook', :from => "2007-03-23", :to => "2007-03-23"
464 478 assert_response :success
465 479 assert_template 'index'
466 480 assert_not_nil assigns(:total_hours)
467 481 assert_equal "4.25", "%.2f" % assigns(:total_hours)
468 482 assert_tag :form,
469 483 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
470 484 end
471 485
472 486 def test_index_from_a_date
473 487 get :index, :project_id => 'ecookbook', :from => "2007-03-23", :to => ""
474 488 assert_equal '2007-03-23'.to_date, assigns(:from)
475 489 assert_nil assigns(:to)
476 490 end
477 491
478 492 def test_index_to_a_date
479 493 get :index, :project_id => 'ecookbook', :from => "", :to => "2007-03-23"
480 494 assert_nil assigns(:from)
481 495 assert_equal '2007-03-23'.to_date, assigns(:to)
482 496 end
483 497
484 498 def test_index_today
485 499 Date.stubs(:today).returns('2011-12-15'.to_date)
486 500 get :index, :period => 'today'
487 501 assert_equal '2011-12-15'.to_date, assigns(:from)
488 502 assert_equal '2011-12-15'.to_date, assigns(:to)
489 503 end
490 504
491 505 def test_index_yesterday
492 506 Date.stubs(:today).returns('2011-12-15'.to_date)
493 507 get :index, :period => 'yesterday'
494 508 assert_equal '2011-12-14'.to_date, assigns(:from)
495 509 assert_equal '2011-12-14'.to_date, assigns(:to)
496 510 end
497 511
498 512 def test_index_current_week
499 513 Date.stubs(:today).returns('2011-12-15'.to_date)
500 514 get :index, :period => 'current_week'
501 515 assert_equal '2011-12-12'.to_date, assigns(:from)
502 516 assert_equal '2011-12-18'.to_date, assigns(:to)
503 517 end
504 518
505 519 def test_index_last_week
506 520 Date.stubs(:today).returns('2011-12-15'.to_date)
507 521 get :index, :period => 'current_week'
508 522 assert_equal '2011-12-05'.to_date, assigns(:from)
509 523 assert_equal '2011-12-11'.to_date, assigns(:to)
510 524 end
511 525
512 526 def test_index_last_week
513 527 Date.stubs(:today).returns('2011-12-15'.to_date)
514 528 get :index, :period => 'last_week'
515 529 assert_equal '2011-12-05'.to_date, assigns(:from)
516 530 assert_equal '2011-12-11'.to_date, assigns(:to)
517 531 end
518 532
519 533 def test_index_7_days
520 534 Date.stubs(:today).returns('2011-12-15'.to_date)
521 535 get :index, :period => '7_days'
522 536 assert_equal '2011-12-08'.to_date, assigns(:from)
523 537 assert_equal '2011-12-15'.to_date, assigns(:to)
524 538 end
525 539
526 540 def test_index_current_month
527 541 Date.stubs(:today).returns('2011-12-15'.to_date)
528 542 get :index, :period => 'current_month'
529 543 assert_equal '2011-12-01'.to_date, assigns(:from)
530 544 assert_equal '2011-12-31'.to_date, assigns(:to)
531 545 end
532 546
533 547 def test_index_last_month
534 548 Date.stubs(:today).returns('2011-12-15'.to_date)
535 549 get :index, :period => 'last_month'
536 550 assert_equal '2011-11-01'.to_date, assigns(:from)
537 551 assert_equal '2011-11-30'.to_date, assigns(:to)
538 552 end
539 553
540 554 def test_index_30_days
541 555 Date.stubs(:today).returns('2011-12-15'.to_date)
542 556 get :index, :period => '30_days'
543 557 assert_equal '2011-11-15'.to_date, assigns(:from)
544 558 assert_equal '2011-12-15'.to_date, assigns(:to)
545 559 end
546 560
547 561 def test_index_current_year
548 562 Date.stubs(:today).returns('2011-12-15'.to_date)
549 563 get :index, :period => 'current_year'
550 564 assert_equal '2011-01-01'.to_date, assigns(:from)
551 565 assert_equal '2011-12-31'.to_date, assigns(:to)
552 566 end
553 567
554 568 def test_index_at_issue_level
555 569 get :index, :issue_id => 1
556 570 assert_response :success
557 571 assert_template 'index'
558 572 assert_not_nil assigns(:entries)
559 573 assert_equal 2, assigns(:entries).size
560 574 assert_not_nil assigns(:total_hours)
561 575 assert_equal 154.25, assigns(:total_hours)
562 576 # display all time
563 577 assert_nil assigns(:from)
564 578 assert_nil assigns(:to)
565 579 # TODO: remove /projects/:project_id/issues/:issue_id/time_entries routes
566 580 # to use /issues/:issue_id/time_entries
567 581 assert_tag :form,
568 582 :attributes => {:action => "/projects/ecookbook/issues/1/time_entries", :id => 'query_form'}
569 583 end
570 584
571 585 def test_index_should_sort_by_spent_on_and_created_on
572 586 t1 = TimeEntry.create!(:user => User.find(1), :project => Project.find(1), :hours => 1, :spent_on => '2012-06-16', :created_on => '2012-06-16 20:00:00', :activity_id => 10)
573 587 t2 = TimeEntry.create!(:user => User.find(1), :project => Project.find(1), :hours => 1, :spent_on => '2012-06-16', :created_on => '2012-06-16 20:05:00', :activity_id => 10)
574 588 t3 = TimeEntry.create!(:user => User.find(1), :project => Project.find(1), :hours => 1, :spent_on => '2012-06-15', :created_on => '2012-06-16 20:10:00', :activity_id => 10)
575 589
576 590 get :index, :project_id => 1, :from => '2012-06-15', :to => '2012-06-16'
577 591 assert_response :success
578 592 assert_equal [t2, t1, t3], assigns(:entries)
579 593
580 594 get :index, :project_id => 1, :from => '2012-06-15', :to => '2012-06-16', :sort => 'spent_on'
581 595 assert_response :success
582 596 assert_equal [t3, t1, t2], assigns(:entries)
583 597 end
584 598
585 599 def test_index_atom_feed
586 600 get :index, :project_id => 1, :format => 'atom'
587 601 assert_response :success
588 602 assert_equal 'application/atom+xml', @response.content_type
589 603 assert_not_nil assigns(:items)
590 604 assert assigns(:items).first.is_a?(TimeEntry)
591 605 end
592 606
593 607 def test_index_all_projects_csv_export
594 608 Setting.date_format = '%m/%d/%Y'
595 609 get :index, :format => 'csv'
596 610 assert_response :success
597 611 assert_equal 'text/csv; header=present', @response.content_type
598 612 assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment,Overtime\n")
599 613 assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\",\"\"\n")
600 614 end
601 615
602 616 def test_index_csv_export
603 617 Setting.date_format = '%m/%d/%Y'
604 618 get :index, :project_id => 1, :format => 'csv'
605 619 assert_response :success
606 620 assert_equal 'text/csv; header=present', @response.content_type
607 621 assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment,Overtime\n")
608 622 assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\",\"\"\n")
609 623 end
610 624
611 625 def test_index_csv_export_with_multi_custom_field
612 626 field = TimeEntryCustomField.create!(:name => 'Test', :field_format => 'list',
613 627 :multiple => true, :possible_values => ['value1', 'value2'])
614 628 entry = TimeEntry.find(1)
615 629 entry.custom_field_values = {field.id => ['value1', 'value2']}
616 630 entry.save!
617 631
618 632 get :index, :project_id => 1, :format => 'csv'
619 633 assert_response :success
620 634 assert_include '"value1, value2"', @response.body
621 635 end
622 636
623 637 def test_csv_big_5
624 638 user = User.find_by_id(3)
625 639 user.language = "zh-TW"
626 640 assert user.save
627 641 str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88"
628 642 str_big5 = "\xa4@\xa4\xeb"
629 643 if str_utf8.respond_to?(:force_encoding)
630 644 str_utf8.force_encoding('UTF-8')
631 645 str_big5.force_encoding('Big5')
632 646 end
633 647 @request.session[:user_id] = 3
634 648 post :create, :project_id => 1,
635 649 :time_entry => {:comments => str_utf8,
636 650 # Not the default activity
637 651 :activity_id => '11',
638 652 :issue_id => '',
639 653 :spent_on => '2011-11-10',
640 654 :hours => '7.3'}
641 655 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
642 656
643 657 t = TimeEntry.find_by_comments(str_utf8)
644 658 assert_not_nil t
645 659 assert_equal 11, t.activity_id
646 660 assert_equal 7.3, t.hours
647 661 assert_equal 3, t.user_id
648 662
649 663 get :index, :project_id => 1, :format => 'csv',
650 664 :from => '2011-11-10', :to => '2011-11-10'
651 665 assert_response :success
652 666 assert_equal 'text/csv; header=present', @response.content_type
653 667 ar = @response.body.chomp.split("\n")
654 668 s1 = "\xa4\xe9\xb4\xc1"
655 669 if str_utf8.respond_to?(:force_encoding)
656 670 s1.force_encoding('Big5')
657 671 end
658 672 assert ar[0].include?(s1)
659 673 assert ar[1].include?(str_big5)
660 674 end
661 675
662 676 def test_csv_cannot_convert_should_be_replaced_big_5
663 677 user = User.find_by_id(3)
664 678 user.language = "zh-TW"
665 679 assert user.save
666 680 str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85"
667 681 if str_utf8.respond_to?(:force_encoding)
668 682 str_utf8.force_encoding('UTF-8')
669 683 end
670 684 @request.session[:user_id] = 3
671 685 post :create, :project_id => 1,
672 686 :time_entry => {:comments => str_utf8,
673 687 # Not the default activity
674 688 :activity_id => '11',
675 689 :issue_id => '',
676 690 :spent_on => '2011-11-10',
677 691 :hours => '7.3'}
678 692 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
679 693
680 694 t = TimeEntry.find_by_comments(str_utf8)
681 695 assert_not_nil t
682 696 assert_equal 11, t.activity_id
683 697 assert_equal 7.3, t.hours
684 698 assert_equal 3, t.user_id
685 699
686 700 get :index, :project_id => 1, :format => 'csv',
687 701 :from => '2011-11-10', :to => '2011-11-10'
688 702 assert_response :success
689 703 assert_equal 'text/csv; header=present', @response.content_type
690 704 ar = @response.body.chomp.split("\n")
691 705 s1 = "\xa4\xe9\xb4\xc1"
692 706 if str_utf8.respond_to?(:force_encoding)
693 707 s1.force_encoding('Big5')
694 708 end
695 709 assert ar[0].include?(s1)
696 710 s2 = ar[1].split(",")[8]
697 711 if s2.respond_to?(:force_encoding)
698 712 s3 = "\xa5H?"
699 713 s3.force_encoding('Big5')
700 714 assert_equal s3, s2
701 715 elsif RUBY_PLATFORM == 'java'
702 716 assert_equal "??", s2
703 717 else
704 718 assert_equal "\xa5H???", s2
705 719 end
706 720 end
707 721
708 722 def test_csv_tw
709 723 with_settings :default_language => "zh-TW" do
710 724 str1 = "test_csv_tw"
711 725 user = User.find_by_id(3)
712 726 te1 = TimeEntry.create(:spent_on => '2011-11-10',
713 727 :hours => 999.9,
714 728 :project => Project.find(1),
715 729 :user => user,
716 730 :activity => TimeEntryActivity.find_by_name('Design'),
717 731 :comments => str1)
718 732 te2 = TimeEntry.find_by_comments(str1)
719 733 assert_not_nil te2
720 734 assert_equal 999.9, te2.hours
721 735 assert_equal 3, te2.user_id
722 736
723 737 get :index, :project_id => 1, :format => 'csv',
724 738 :from => '2011-11-10', :to => '2011-11-10'
725 739 assert_response :success
726 740 assert_equal 'text/csv; header=present', @response.content_type
727 741
728 742 ar = @response.body.chomp.split("\n")
729 743 s2 = ar[1].split(",")[7]
730 744 assert_equal '999.9', s2
731 745
732 746 str_tw = "Traditional Chinese (\xe7\xb9\x81\xe9\xab\x94\xe4\xb8\xad\xe6\x96\x87)"
733 747 if str_tw.respond_to?(:force_encoding)
734 748 str_tw.force_encoding('UTF-8')
735 749 end
736 750 assert_equal str_tw, l(:general_lang_name)
737 751 assert_equal ',', l(:general_csv_separator)
738 752 assert_equal '.', l(:general_csv_decimal_separator)
739 753 end
740 754 end
741 755
742 756 def test_csv_fr
743 757 with_settings :default_language => "fr" do
744 758 str1 = "test_csv_fr"
745 759 user = User.find_by_id(3)
746 760 te1 = TimeEntry.create(:spent_on => '2011-11-10',
747 761 :hours => 999.9,
748 762 :project => Project.find(1),
749 763 :user => user,
750 764 :activity => TimeEntryActivity.find_by_name('Design'),
751 765 :comments => str1)
752 766 te2 = TimeEntry.find_by_comments(str1)
753 767 assert_not_nil te2
754 768 assert_equal 999.9, te2.hours
755 769 assert_equal 3, te2.user_id
756 770
757 771 get :index, :project_id => 1, :format => 'csv',
758 772 :from => '2011-11-10', :to => '2011-11-10'
759 773 assert_response :success
760 774 assert_equal 'text/csv; header=present', @response.content_type
761 775
762 776 ar = @response.body.chomp.split("\n")
763 777 s2 = ar[1].split(";")[7]
764 778 assert_equal '999,9', s2
765 779
766 780 str_fr = "Fran\xc3\xa7ais"
767 781 if str_fr.respond_to?(:force_encoding)
768 782 str_fr.force_encoding('UTF-8')
769 783 end
770 784 assert_equal str_fr, l(:general_lang_name)
771 785 assert_equal ';', l(:general_csv_separator)
772 786 assert_equal ',', l(:general_csv_decimal_separator)
773 787 end
774 788 end
775 789 end
General Comments 0
You need to be logged in to leave comments. Login now