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