Mercurial > hg > soundsoftware-site
comparison test/functional/timelog_controller_test.rb @ 1298:4f746d8966dd redmine_2.3_integration
Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author | Chris Cannam |
---|---|
date | Fri, 14 Jun 2013 09:28:30 +0100 |
parents | 622f24f53b42 |
children |
comparison
equal
deleted
inserted
replaced
1297:0a574315af3e | 1298:4f746d8966dd |
---|---|
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 |
438 assert_equal 4, assigns(:entries).size | 437 assert_equal 4, assigns(:entries).size |
439 # project and subproject | 438 # project and subproject |
440 assert_equal [1, 3], assigns(:entries).collect(&:project_id).uniq.sort | 439 assert_equal [1, 3], assigns(:entries).collect(&:project_id).uniq.sort |
441 assert_not_nil assigns(:total_hours) | 440 assert_not_nil assigns(:total_hours) |
442 assert_equal "162.90", "%.2f" % assigns(:total_hours) | 441 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, | 442 assert_tag :form, |
447 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'} | 443 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'} |
448 end | 444 end |
449 | 445 |
450 def test_index_at_project_level_with_date_range | 446 def test_index_at_project_level_with_date_range |
451 get :index, :project_id => 'ecookbook', :from => '2007-03-20', :to => '2007-04-30' | 447 get :index, :project_id => 'ecookbook', |
448 :f => ['spent_on'], | |
449 :op => {'spent_on' => '><'}, | |
450 :v => {'spent_on' => ['2007-03-20', '2007-04-30']} | |
452 assert_response :success | 451 assert_response :success |
453 assert_template 'index' | 452 assert_template 'index' |
454 assert_not_nil assigns(:entries) | 453 assert_not_nil assigns(:entries) |
455 assert_equal 3, assigns(:entries).size | 454 assert_equal 3, assigns(:entries).size |
456 assert_not_nil assigns(:total_hours) | 455 assert_not_nil assigns(:total_hours) |
457 assert_equal "12.90", "%.2f" % assigns(:total_hours) | 456 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, | 457 assert_tag :form, |
461 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'} | 458 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'} |
462 end | 459 end |
463 | 460 |
461 def test_index_at_project_level_with_date_range_using_from_and_to_params | |
462 get :index, :project_id => 'ecookbook', :from => '2007-03-20', :to => '2007-04-30' | |
463 assert_response :success | |
464 assert_template 'index' | |
465 assert_not_nil assigns(:entries) | |
466 assert_equal 3, assigns(:entries).size | |
467 assert_not_nil assigns(:total_hours) | |
468 assert_equal "12.90", "%.2f" % assigns(:total_hours) | |
469 assert_tag :form, | |
470 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'} | |
471 end | |
472 | |
464 def test_index_at_project_level_with_period | 473 def test_index_at_project_level_with_period |
465 get :index, :project_id => 'ecookbook', :period => '7_days' | 474 get :index, :project_id => 'ecookbook', |
475 :f => ['spent_on'], | |
476 :op => {'spent_on' => '>t-'}, | |
477 :v => {'spent_on' => ['7']} | |
466 assert_response :success | 478 assert_response :success |
467 assert_template 'index' | 479 assert_template 'index' |
468 assert_not_nil assigns(:entries) | 480 assert_not_nil assigns(:entries) |
469 assert_not_nil assigns(:total_hours) | 481 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, | 482 assert_tag :form, |
473 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'} | 483 :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 | 484 end |
567 | 485 |
568 def test_index_at_issue_level | 486 def test_index_at_issue_level |
569 get :index, :issue_id => 1 | 487 get :index, :issue_id => 1 |
570 assert_response :success | 488 assert_response :success |
585 def test_index_should_sort_by_spent_on_and_created_on | 503 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) | 504 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) | 505 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) | 506 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 | 507 |
590 get :index, :project_id => 1, :from => '2012-06-15', :to => '2012-06-16' | 508 get :index, :project_id => 1, |
509 :f => ['spent_on'], | |
510 :op => {'spent_on' => '><'}, | |
511 :v => {'spent_on' => ['2012-06-15', '2012-06-16']} | |
591 assert_response :success | 512 assert_response :success |
592 assert_equal [t2, t1, t3], assigns(:entries) | 513 assert_equal [t2, t1, t3], assigns(:entries) |
593 | 514 |
594 get :index, :project_id => 1, :from => '2012-06-15', :to => '2012-06-16', :sort => 'spent_on' | 515 get :index, :project_id => 1, |
516 :f => ['spent_on'], | |
517 :op => {'spent_on' => '><'}, | |
518 :v => {'spent_on' => ['2012-06-15', '2012-06-16']}, | |
519 :sort => 'spent_on' | |
595 assert_response :success | 520 assert_response :success |
596 assert_equal [t3, t1, t2], assigns(:entries) | 521 assert_equal [t3, t1, t2], assigns(:entries) |
522 end | |
523 | |
524 def test_index_with_filter_on_issue_custom_field | |
525 issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {2 => 'filter_on_issue_custom_field'}) | |
526 entry = TimeEntry.generate!(:issue => issue, :hours => 2.5) | |
527 | |
528 get :index, :f => ['issue.cf_2'], :op => {'issue.cf_2' => '='}, :v => {'issue.cf_2' => ['filter_on_issue_custom_field']} | |
529 assert_response :success | |
530 assert_equal [entry], assigns(:entries) | |
531 end | |
532 | |
533 def test_index_with_issue_custom_field_column | |
534 issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {2 => 'filter_on_issue_custom_field'}) | |
535 entry = TimeEntry.generate!(:issue => issue, :hours => 2.5) | |
536 | |
537 get :index, :c => %w(project spent_on issue comments hours issue.cf_2) | |
538 assert_response :success | |
539 assert_include :'issue.cf_2', assigns(:query).column_names | |
540 assert_select 'td.issue_cf_2', :text => 'filter_on_issue_custom_field' | |
597 end | 541 end |
598 | 542 |
599 def test_index_atom_feed | 543 def test_index_atom_feed |
600 get :index, :project_id => 1, :format => 'atom' | 544 get :index, :project_id => 1, :format => 'atom' |
601 assert_response :success | 545 assert_response :success |
602 assert_equal 'application/atom+xml', @response.content_type | 546 assert_equal 'application/atom+xml', @response.content_type |
603 assert_not_nil assigns(:items) | 547 assert_not_nil assigns(:items) |
604 assert assigns(:items).first.is_a?(TimeEntry) | 548 assert assigns(:items).first.is_a?(TimeEntry) |
605 end | 549 end |
606 | 550 |
607 def test_index_all_projects_csv_export | 551 def test_index_at_project_level_should_include_csv_export_dialog |
552 get :index, :project_id => 'ecookbook', | |
553 :f => ['spent_on'], | |
554 :op => {'spent_on' => '>='}, | |
555 :v => {'spent_on' => ['2007-04-01']}, | |
556 :c => ['spent_on', 'user'] | |
557 assert_response :success | |
558 | |
559 assert_select '#csv-export-options' do | |
560 assert_select 'form[action=?][method=get]', '/projects/ecookbook/time_entries.csv' do | |
561 # filter | |
562 assert_select 'input[name=?][value=?]', 'f[]', 'spent_on' | |
563 assert_select 'input[name=?][value=?]', 'op[spent_on]', '>=' | |
564 assert_select 'input[name=?][value=?]', 'v[spent_on][]', '2007-04-01' | |
565 # columns | |
566 assert_select 'input[name=?][value=?]', 'c[]', 'spent_on' | |
567 assert_select 'input[name=?][value=?]', 'c[]', 'user' | |
568 assert_select 'input[name=?]', 'c[]', 2 | |
569 end | |
570 end | |
571 end | |
572 | |
573 def test_index_cross_project_should_include_csv_export_dialog | |
574 get :index | |
575 assert_response :success | |
576 | |
577 assert_select '#csv-export-options' do | |
578 assert_select 'form[action=?][method=get]', '/time_entries.csv' | |
579 end | |
580 end | |
581 | |
582 def test_index_at_issue_level_should_include_csv_export_dialog | |
583 get :index, :project_id => 'ecookbook', :issue_id => 3 | |
584 assert_response :success | |
585 | |
586 assert_select '#csv-export-options' do | |
587 assert_select 'form[action=?][method=get]', '/projects/ecookbook/issues/3/time_entries.csv' | |
588 end | |
589 end | |
590 | |
591 def test_index_csv_all_projects | |
608 Setting.date_format = '%m/%d/%Y' | 592 Setting.date_format = '%m/%d/%Y' |
609 get :index, :format => 'csv' | 593 get :index, :format => 'csv' |
610 assert_response :success | 594 assert_response :success |
611 assert_equal 'text/csv; header=present', @response.content_type | 595 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") | 596 end |
613 assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\",\"\"\n") | 597 |
614 end | 598 def test_index_csv |
615 | |
616 def test_index_csv_export | |
617 Setting.date_format = '%m/%d/%Y' | 599 Setting.date_format = '%m/%d/%Y' |
618 get :index, :project_id => 1, :format => 'csv' | 600 get :index, :project_id => 1, :format => 'csv' |
619 assert_response :success | 601 assert_response :success |
620 assert_equal 'text/csv; header=present', @response.content_type | 602 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 | 603 end |
789 end | 604 end |