comparison test/functional/timelog_controller_test.rb @ 1464:261b3d9a4903 redmine-2.4

Update to Redmine 2.4 branch rev 12663
author Chris Cannam
date Tue, 14 Jan 2014 14:37:42 +0000
parents 433d4f72a19b
children e248c7af89ec
comparison
equal deleted inserted replaced
1296:038ba2d95de8 1464:261b3d9a4903
1 # -*- coding: utf-8 -*- 1 # -*- coding: utf-8 -*-
2 # Redmine - project management software 2 # Redmine - project management software
3 # Copyright (C) 2006-2012 Jean-Philippe Lang 3 # Copyright (C) 2006-2013 Jean-Philippe Lang
4 # 4 #
5 # This program is free software; you can redistribute it and/or 5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License 6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2 7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version. 8 # of the License, or (at your option) any later version.
15 # You should have received a copy of the GNU General Public License 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 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. 17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 18
19 require File.expand_path('../../test_helper', __FILE__) 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 20
25 class TimelogControllerTest < ActionController::TestCase 21 class TimelogControllerTest < ActionController::TestCase
26 fixtures :projects, :enabled_modules, :roles, :members, 22 fixtures :projects, :enabled_modules, :roles, :members,
27 :member_roles, :issues, :time_entries, :users, 23 :member_roles, :issues, :time_entries, :users,
28 :trackers, :enumerations, :issue_statuses, 24 :trackers, :enumerations, :issue_statuses,
29 :custom_fields, :custom_values 25 :custom_fields, :custom_values,
26 :projects_trackers, :custom_fields_trackers,
27 :custom_fields_projects
30 28
31 include Redmine::I18n 29 include Redmine::I18n
32
33 def setup
34 @controller = TimelogController.new
35 @request = ActionController::TestRequest.new
36 @response = ActionController::TestResponse.new
37 end
38 30
39 def test_new_with_project_id 31 def test_new_with_project_id
40 @request.session[:user_id] = 3 32 @request.session[:user_id] = 3
41 get :new, :project_id => 1 33 get :new, :project_id => 1
42 assert_response :success 34 assert_response :success
301 @request.session[:user_id] = 2 293 @request.session[:user_id] = 2
302 get :bulk_edit, :ids => [1, 2] 294 get :bulk_edit, :ids => [1, 2]
303 assert_response :success 295 assert_response :success
304 assert_template 'bulk_edit' 296 assert_template 'bulk_edit'
305 297
306 # System wide custom field 298 assert_select 'ul#bulk-selection' do
307 assert_tag :select, :attributes => {:name => 'time_entry[custom_field_values][10]'} 299 assert_select 'li', 2
308 300 assert_select 'li a', :text => '03/23/2007 - eCookbook: 4.25 hours'
309 # Activities 301 end
310 assert_select 'select[name=?]', 'time_entry[activity_id]' do 302
311 assert_select 'option[value=]', :text => '(No change)' 303 assert_select 'form#bulk_edit_form[action=?]', '/time_entries/bulk_update' do
312 assert_select 'option[value=9]', :text => 'Design' 304 # System wide custom field
305 assert_select 'select[name=?]', 'time_entry[custom_field_values][10]'
306
307 # Activities
308 assert_select 'select[name=?]', 'time_entry[activity_id]' do
309 assert_select 'option[value=]', :text => '(No change)'
310 assert_select 'option[value=9]', :text => 'Design'
311 end
313 end 312 end
314 end 313 end
315 314
316 def test_get_bulk_edit_on_different_projects 315 def test_get_bulk_edit_on_different_projects
317 @request.session[:user_id] = 2 316 @request.session[:user_id] = 2
428 assert_response :success 427 assert_response :success
429 assert_template 'index' 428 assert_template 'index'
430 assert_tag 'a', :attributes => {:href => '/time_entries/new'}, :content => /Log time/ 429 assert_tag 'a', :attributes => {:href => '/time_entries/new'}, :content => /Log time/
431 end 430 end
432 431
432 def test_index_my_spent_time
433 @request.session[:user_id] = 2
434 get :index, :user_id => 'me'
435 assert_response :success
436 assert_template 'index'
437 assert assigns(:entries).all? {|entry| entry.user_id == 2}
438 end
439
433 def test_index_at_project_level 440 def test_index_at_project_level
434 get :index, :project_id => 'ecookbook' 441 get :index, :project_id => 'ecookbook'
435 assert_response :success 442 assert_response :success
436 assert_template 'index' 443 assert_template 'index'
437 assert_not_nil assigns(:entries) 444 assert_not_nil assigns(:entries)
438 assert_equal 4, assigns(:entries).size 445 assert_equal 4, assigns(:entries).size
439 # project and subproject 446 # project and subproject
440 assert_equal [1, 3], assigns(:entries).collect(&:project_id).uniq.sort 447 assert_equal [1, 3], assigns(:entries).collect(&:project_id).uniq.sort
441 assert_not_nil assigns(:total_hours) 448 assert_not_nil assigns(:total_hours)
442 assert_equal "162.90", "%.2f" % assigns(:total_hours) 449 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, 450 assert_tag :form,
447 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'} 451 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
448 end 452 end
449 453
454 def test_index_with_display_subprojects_issues_to_false_should_not_include_subproject_entries
455 entry = TimeEntry.generate!(:project => Project.find(3))
456
457 with_settings :display_subprojects_issues => '0' do
458 get :index, :project_id => 'ecookbook'
459 assert_response :success
460 assert_template 'index'
461 assert_not_include entry, assigns(:entries)
462 end
463 end
464
465 def test_index_with_display_subprojects_issues_to_false_and_subproject_filter_should_include_subproject_entries
466 entry = TimeEntry.generate!(:project => Project.find(3))
467
468 with_settings :display_subprojects_issues => '0' do
469 get :index, :project_id => 'ecookbook', :subproject_id => 3
470 assert_response :success
471 assert_template 'index'
472 assert_include entry, assigns(:entries)
473 end
474 end
475
450 def test_index_at_project_level_with_date_range 476 def test_index_at_project_level_with_date_range
451 get :index, :project_id => 'ecookbook', :from => '2007-03-20', :to => '2007-04-30' 477 get :index, :project_id => 'ecookbook',
478 :f => ['spent_on'],
479 :op => {'spent_on' => '><'},
480 :v => {'spent_on' => ['2007-03-20', '2007-04-30']}
452 assert_response :success 481 assert_response :success
453 assert_template 'index' 482 assert_template 'index'
454 assert_not_nil assigns(:entries) 483 assert_not_nil assigns(:entries)
455 assert_equal 3, assigns(:entries).size 484 assert_equal 3, assigns(:entries).size
456 assert_not_nil assigns(:total_hours) 485 assert_not_nil assigns(:total_hours)
457 assert_equal "12.90", "%.2f" % assigns(:total_hours) 486 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, 487 assert_tag :form,
461 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'} 488 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
462 end 489 end
463 490
491 def test_index_at_project_level_with_date_range_using_from_and_to_params
492 get :index, :project_id => 'ecookbook', :from => '2007-03-20', :to => '2007-04-30'
493 assert_response :success
494 assert_template 'index'
495 assert_not_nil assigns(:entries)
496 assert_equal 3, assigns(:entries).size
497 assert_not_nil assigns(:total_hours)
498 assert_equal "12.90", "%.2f" % assigns(:total_hours)
499 assert_tag :form,
500 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
501 end
502
464 def test_index_at_project_level_with_period 503 def test_index_at_project_level_with_period
465 get :index, :project_id => 'ecookbook', :period => '7_days' 504 get :index, :project_id => 'ecookbook',
505 :f => ['spent_on'],
506 :op => {'spent_on' => '>t-'},
507 :v => {'spent_on' => ['7']}
466 assert_response :success 508 assert_response :success
467 assert_template 'index' 509 assert_template 'index'
468 assert_not_nil assigns(:entries) 510 assert_not_nil assigns(:entries)
469 assert_not_nil assigns(:total_hours) 511 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, 512 assert_tag :form,
473 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'} 513 :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 514 end
567 515
568 def test_index_at_issue_level 516 def test_index_at_issue_level
569 get :index, :issue_id => 1 517 get :index, :issue_id => 1
570 assert_response :success 518 assert_response :success
585 def test_index_should_sort_by_spent_on_and_created_on 533 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) 534 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) 535 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) 536 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 537
590 get :index, :project_id => 1, :from => '2012-06-15', :to => '2012-06-16' 538 get :index, :project_id => 1,
539 :f => ['spent_on'],
540 :op => {'spent_on' => '><'},
541 :v => {'spent_on' => ['2012-06-15', '2012-06-16']}
591 assert_response :success 542 assert_response :success
592 assert_equal [t2, t1, t3], assigns(:entries) 543 assert_equal [t2, t1, t3], assigns(:entries)
593 544
594 get :index, :project_id => 1, :from => '2012-06-15', :to => '2012-06-16', :sort => 'spent_on' 545 get :index, :project_id => 1,
546 :f => ['spent_on'],
547 :op => {'spent_on' => '><'},
548 :v => {'spent_on' => ['2012-06-15', '2012-06-16']},
549 :sort => 'spent_on'
595 assert_response :success 550 assert_response :success
596 assert_equal [t3, t1, t2], assigns(:entries) 551 assert_equal [t3, t1, t2], assigns(:entries)
552 end
553
554 def test_index_with_filter_on_issue_custom_field
555 issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {2 => 'filter_on_issue_custom_field'})
556 entry = TimeEntry.generate!(:issue => issue, :hours => 2.5)
557
558 get :index, :f => ['issue.cf_2'], :op => {'issue.cf_2' => '='}, :v => {'issue.cf_2' => ['filter_on_issue_custom_field']}
559 assert_response :success
560 assert_equal [entry], assigns(:entries)
561 end
562
563 def test_index_with_issue_custom_field_column
564 issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {2 => 'filter_on_issue_custom_field'})
565 entry = TimeEntry.generate!(:issue => issue, :hours => 2.5)
566
567 get :index, :c => %w(project spent_on issue comments hours issue.cf_2)
568 assert_response :success
569 assert_include :'issue.cf_2', assigns(:query).column_names
570 assert_select 'td.issue_cf_2', :text => 'filter_on_issue_custom_field'
571 end
572
573 def test_index_with_time_entry_custom_field_column
574 field = TimeEntryCustomField.generate!(:field_format => 'string')
575 entry = TimeEntry.generate!(:hours => 2.5, :custom_field_values => {field.id => 'CF Value'})
576 field_name = "cf_#{field.id}"
577
578 get :index, :c => ["hours", field_name]
579 assert_response :success
580 assert_include field_name.to_sym, assigns(:query).column_names
581 assert_select "td.#{field_name}", :text => 'CF Value'
582 end
583
584 def test_index_with_time_entry_custom_field_sorting
585 field = TimeEntryCustomField.generate!(:field_format => 'string', :name => 'String Field')
586 TimeEntry.generate!(:hours => 2.5, :custom_field_values => {field.id => 'CF Value 1'})
587 TimeEntry.generate!(:hours => 2.5, :custom_field_values => {field.id => 'CF Value 3'})
588 TimeEntry.generate!(:hours => 2.5, :custom_field_values => {field.id => 'CF Value 2'})
589 field_name = "cf_#{field.id}"
590
591 get :index, :c => ["hours", field_name], :sort => field_name
592 assert_response :success
593 assert_include field_name.to_sym, assigns(:query).column_names
594 assert_select "th a.sort", :text => 'String Field'
595
596 # Make sure that values are properly sorted
597 values = assigns(:entries).map {|e| e.custom_field_value(field)}.compact
598 assert_equal 3, values.size
599 assert_equal values.sort, values
597 end 600 end
598 601
599 def test_index_atom_feed 602 def test_index_atom_feed
600 get :index, :project_id => 1, :format => 'atom' 603 get :index, :project_id => 1, :format => 'atom'
601 assert_response :success 604 assert_response :success
602 assert_equal 'application/atom+xml', @response.content_type 605 assert_equal 'application/atom+xml', @response.content_type
603 assert_not_nil assigns(:items) 606 assert_not_nil assigns(:items)
604 assert assigns(:items).first.is_a?(TimeEntry) 607 assert assigns(:items).first.is_a?(TimeEntry)
605 end 608 end
606 609
607 def test_index_all_projects_csv_export 610 def test_index_at_project_level_should_include_csv_export_dialog
611 get :index, :project_id => 'ecookbook',
612 :f => ['spent_on'],
613 :op => {'spent_on' => '>='},
614 :v => {'spent_on' => ['2007-04-01']},
615 :c => ['spent_on', 'user']
616 assert_response :success
617
618 assert_select '#csv-export-options' do
619 assert_select 'form[action=?][method=get]', '/projects/ecookbook/time_entries.csv' do
620 # filter
621 assert_select 'input[name=?][value=?]', 'f[]', 'spent_on'
622 assert_select 'input[name=?][value=?]', 'op[spent_on]', '&gt;='
623 assert_select 'input[name=?][value=?]', 'v[spent_on][]', '2007-04-01'
624 # columns
625 assert_select 'input[name=?][value=?]', 'c[]', 'spent_on'
626 assert_select 'input[name=?][value=?]', 'c[]', 'user'
627 assert_select 'input[name=?]', 'c[]', 2
628 end
629 end
630 end
631
632 def test_index_cross_project_should_include_csv_export_dialog
633 get :index
634 assert_response :success
635
636 assert_select '#csv-export-options' do
637 assert_select 'form[action=?][method=get]', '/time_entries.csv'
638 end
639 end
640
641 def test_index_at_issue_level_should_include_csv_export_dialog
642 get :index, :project_id => 'ecookbook', :issue_id => 3
643 assert_response :success
644
645 assert_select '#csv-export-options' do
646 assert_select 'form[action=?][method=get]', '/projects/ecookbook/issues/3/time_entries.csv'
647 end
648 end
649
650 def test_index_csv_all_projects
608 Setting.date_format = '%m/%d/%Y' 651 Setting.date_format = '%m/%d/%Y'
609 get :index, :format => 'csv' 652 get :index, :format => 'csv'
610 assert_response :success 653 assert_response :success
611 assert_equal 'text/csv; header=present', @response.content_type 654 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") 655 end
613 assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\",\"\"\n") 656
614 end 657 def test_index_csv
615
616 def test_index_csv_export
617 Setting.date_format = '%m/%d/%Y' 658 Setting.date_format = '%m/%d/%Y'
618 get :index, :project_id => 1, :format => 'csv' 659 get :index, :project_id => 1, :format => 'csv'
619 assert_response :success 660 assert_response :success
620 assert_equal 'text/csv; header=present', @response.content_type 661 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 662 end
789 end 663 end