Mercurial > hg > soundsoftware-site
diff test/functional/timelog_controller_test.rb @ 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 | 433d4f72a19b |
children |
line wrap: on
line diff
--- a/test/functional/timelog_controller_test.rb Fri Jun 14 09:01:12 2013 +0100 +++ b/test/functional/timelog_controller_test.rb Fri Jun 14 09:02:21 2013 +0100 @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # Redmine - project management software -# Copyright (C) 2006-2012 Jean-Philippe Lang +# Copyright (C) 2006-2013 Jean-Philippe Lang # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -17,25 +17,17 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. require File.expand_path('../../test_helper', __FILE__) -require 'timelog_controller' - -# Re-raise errors caught by the controller. -class TimelogController; def rescue_action(e) raise e end; end class TimelogControllerTest < ActionController::TestCase fixtures :projects, :enabled_modules, :roles, :members, :member_roles, :issues, :time_entries, :users, :trackers, :enumerations, :issue_statuses, - :custom_fields, :custom_values + :custom_fields, :custom_values, + :projects_trackers, :custom_fields_trackers, + :custom_fields_projects include Redmine::I18n - def setup - @controller = TimelogController.new - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new - end - def test_new_with_project_id @request.session[:user_id] = 3 get :new, :project_id => 1 @@ -303,13 +295,20 @@ assert_response :success assert_template 'bulk_edit' - # System wide custom field - assert_tag :select, :attributes => {:name => 'time_entry[custom_field_values][10]'} + assert_select 'ul#bulk-selection' do + assert_select 'li', 2 + assert_select 'li a', :text => '03/23/2007 - eCookbook: 4.25 hours' + end - # Activities - assert_select 'select[name=?]', 'time_entry[activity_id]' do - assert_select 'option[value=]', :text => '(No change)' - assert_select 'option[value=9]', :text => 'Design' + assert_select 'form#bulk_edit_form[action=?]', '/time_entries/bulk_update' do + # System wide custom field + assert_select 'select[name=?]', 'time_entry[custom_field_values][10]' + + # Activities + assert_select 'select[name=?]', 'time_entry[activity_id]' do + assert_select 'option[value=]', :text => '(No change)' + assert_select 'option[value=9]', :text => 'Design' + end end end @@ -440,14 +439,26 @@ assert_equal [1, 3], assigns(:entries).collect(&:project_id).uniq.sort assert_not_nil assigns(:total_hours) assert_equal "162.90", "%.2f" % assigns(:total_hours) - # display all time by default - assert_nil assigns(:from) - assert_nil assigns(:to) assert_tag :form, :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'} end def test_index_at_project_level_with_date_range + get :index, :project_id => 'ecookbook', + :f => ['spent_on'], + :op => {'spent_on' => '><'}, + :v => {'spent_on' => ['2007-03-20', '2007-04-30']} + assert_response :success + assert_template 'index' + assert_not_nil assigns(:entries) + assert_equal 3, assigns(:entries).size + assert_not_nil assigns(:total_hours) + assert_equal "12.90", "%.2f" % assigns(:total_hours) + assert_tag :form, + :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'} + end + + def test_index_at_project_level_with_date_range_using_from_and_to_params get :index, :project_id => 'ecookbook', :from => '2007-03-20', :to => '2007-04-30' assert_response :success assert_template 'index' @@ -455,116 +466,23 @@ assert_equal 3, assigns(:entries).size assert_not_nil assigns(:total_hours) assert_equal "12.90", "%.2f" % assigns(:total_hours) - assert_equal '2007-03-20'.to_date, assigns(:from) - assert_equal '2007-04-30'.to_date, assigns(:to) assert_tag :form, :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'} end def test_index_at_project_level_with_period - get :index, :project_id => 'ecookbook', :period => '7_days' + get :index, :project_id => 'ecookbook', + :f => ['spent_on'], + :op => {'spent_on' => '>t-'}, + :v => {'spent_on' => ['7']} assert_response :success assert_template 'index' assert_not_nil assigns(:entries) assert_not_nil assigns(:total_hours) - assert_equal Date.today - 7, assigns(:from) - assert_equal Date.today, assigns(:to) assert_tag :form, :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'} end - def test_index_one_day - get :index, :project_id => 'ecookbook', :from => "2007-03-23", :to => "2007-03-23" - assert_response :success - assert_template 'index' - assert_not_nil assigns(:total_hours) - assert_equal "4.25", "%.2f" % assigns(:total_hours) - assert_tag :form, - :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'} - end - - def test_index_from_a_date - get :index, :project_id => 'ecookbook', :from => "2007-03-23", :to => "" - assert_equal '2007-03-23'.to_date, assigns(:from) - assert_nil assigns(:to) - end - - def test_index_to_a_date - get :index, :project_id => 'ecookbook', :from => "", :to => "2007-03-23" - assert_nil assigns(:from) - assert_equal '2007-03-23'.to_date, assigns(:to) - end - - def test_index_today - Date.stubs(:today).returns('2011-12-15'.to_date) - get :index, :period => 'today' - assert_equal '2011-12-15'.to_date, assigns(:from) - assert_equal '2011-12-15'.to_date, assigns(:to) - end - - def test_index_yesterday - Date.stubs(:today).returns('2011-12-15'.to_date) - get :index, :period => 'yesterday' - assert_equal '2011-12-14'.to_date, assigns(:from) - assert_equal '2011-12-14'.to_date, assigns(:to) - end - - def test_index_current_week - Date.stubs(:today).returns('2011-12-15'.to_date) - get :index, :period => 'current_week' - assert_equal '2011-12-12'.to_date, assigns(:from) - assert_equal '2011-12-18'.to_date, assigns(:to) - end - - def test_index_last_week - Date.stubs(:today).returns('2011-12-15'.to_date) - get :index, :period => 'last_week' - assert_equal '2011-12-05'.to_date, assigns(:from) - assert_equal '2011-12-11'.to_date, assigns(:to) - end - - def test_index_last_2_week - Date.stubs(:today).returns('2011-12-15'.to_date) - get :index, :period => 'last_2_weeks' - assert_equal '2011-11-28'.to_date, assigns(:from) - assert_equal '2011-12-11'.to_date, assigns(:to) - end - - def test_index_7_days - Date.stubs(:today).returns('2011-12-15'.to_date) - get :index, :period => '7_days' - assert_equal '2011-12-08'.to_date, assigns(:from) - assert_equal '2011-12-15'.to_date, assigns(:to) - end - - def test_index_current_month - Date.stubs(:today).returns('2011-12-15'.to_date) - get :index, :period => 'current_month' - assert_equal '2011-12-01'.to_date, assigns(:from) - assert_equal '2011-12-31'.to_date, assigns(:to) - end - - def test_index_last_month - Date.stubs(:today).returns('2011-12-15'.to_date) - get :index, :period => 'last_month' - assert_equal '2011-11-01'.to_date, assigns(:from) - assert_equal '2011-11-30'.to_date, assigns(:to) - end - - def test_index_30_days - Date.stubs(:today).returns('2011-12-15'.to_date) - get :index, :period => '30_days' - assert_equal '2011-11-15'.to_date, assigns(:from) - assert_equal '2011-12-15'.to_date, assigns(:to) - end - - def test_index_current_year - Date.stubs(:today).returns('2011-12-15'.to_date) - get :index, :period => 'current_year' - assert_equal '2011-01-01'.to_date, assigns(:from) - assert_equal '2011-12-31'.to_date, assigns(:to) - end - def test_index_at_issue_level get :index, :issue_id => 1 assert_response :success @@ -587,15 +505,41 @@ 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) 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) - get :index, :project_id => 1, :from => '2012-06-15', :to => '2012-06-16' + get :index, :project_id => 1, + :f => ['spent_on'], + :op => {'spent_on' => '><'}, + :v => {'spent_on' => ['2012-06-15', '2012-06-16']} assert_response :success assert_equal [t2, t1, t3], assigns(:entries) - get :index, :project_id => 1, :from => '2012-06-15', :to => '2012-06-16', :sort => 'spent_on' + get :index, :project_id => 1, + :f => ['spent_on'], + :op => {'spent_on' => '><'}, + :v => {'spent_on' => ['2012-06-15', '2012-06-16']}, + :sort => 'spent_on' assert_response :success assert_equal [t3, t1, t2], assigns(:entries) end + def test_index_with_filter_on_issue_custom_field + issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {2 => 'filter_on_issue_custom_field'}) + entry = TimeEntry.generate!(:issue => issue, :hours => 2.5) + + get :index, :f => ['issue.cf_2'], :op => {'issue.cf_2' => '='}, :v => {'issue.cf_2' => ['filter_on_issue_custom_field']} + assert_response :success + assert_equal [entry], assigns(:entries) + end + + def test_index_with_issue_custom_field_column + issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {2 => 'filter_on_issue_custom_field'}) + entry = TimeEntry.generate!(:issue => issue, :hours => 2.5) + + get :index, :c => %w(project spent_on issue comments hours issue.cf_2) + assert_response :success + assert_include :'issue.cf_2', assigns(:query).column_names + assert_select 'td.issue_cf_2', :text => 'filter_on_issue_custom_field' + end + def test_index_atom_feed get :index, :project_id => 1, :format => 'atom' assert_response :success @@ -604,186 +548,57 @@ assert assigns(:items).first.is_a?(TimeEntry) end - def test_index_all_projects_csv_export + def test_index_at_project_level_should_include_csv_export_dialog + get :index, :project_id => 'ecookbook', + :f => ['spent_on'], + :op => {'spent_on' => '>='}, + :v => {'spent_on' => ['2007-04-01']}, + :c => ['spent_on', 'user'] + assert_response :success + + assert_select '#csv-export-options' do + assert_select 'form[action=?][method=get]', '/projects/ecookbook/time_entries.csv' do + # filter + assert_select 'input[name=?][value=?]', 'f[]', 'spent_on' + assert_select 'input[name=?][value=?]', 'op[spent_on]', '>=' + assert_select 'input[name=?][value=?]', 'v[spent_on][]', '2007-04-01' + # columns + assert_select 'input[name=?][value=?]', 'c[]', 'spent_on' + assert_select 'input[name=?][value=?]', 'c[]', 'user' + assert_select 'input[name=?]', 'c[]', 2 + end + end + end + + def test_index_cross_project_should_include_csv_export_dialog + get :index + assert_response :success + + assert_select '#csv-export-options' do + assert_select 'form[action=?][method=get]', '/time_entries.csv' + end + end + + def test_index_at_issue_level_should_include_csv_export_dialog + get :index, :project_id => 'ecookbook', :issue_id => 3 + assert_response :success + + assert_select '#csv-export-options' do + assert_select 'form[action=?][method=get]', '/projects/ecookbook/issues/3/time_entries.csv' + end + end + + def test_index_csv_all_projects Setting.date_format = '%m/%d/%Y' get :index, :format => 'csv' assert_response :success - assert_equal 'text/csv; header=present', @response.content_type - assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment,Overtime\n") - assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\",\"\"\n") + assert_equal 'text/csv; header=present', response.content_type end - def test_index_csv_export + def test_index_csv Setting.date_format = '%m/%d/%Y' get :index, :project_id => 1, :format => 'csv' assert_response :success - assert_equal 'text/csv; header=present', @response.content_type - assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment,Overtime\n") - assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\",\"\"\n") - end - - def test_index_csv_export_with_multi_custom_field - field = TimeEntryCustomField.create!(:name => 'Test', :field_format => 'list', - :multiple => true, :possible_values => ['value1', 'value2']) - entry = TimeEntry.find(1) - entry.custom_field_values = {field.id => ['value1', 'value2']} - entry.save! - - get :index, :project_id => 1, :format => 'csv' - assert_response :success - assert_include '"value1, value2"', @response.body - end - - def test_csv_big_5 - user = User.find_by_id(3) - user.language = "zh-TW" - assert user.save - str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88" - str_big5 = "\xa4@\xa4\xeb" - if str_utf8.respond_to?(:force_encoding) - str_utf8.force_encoding('UTF-8') - str_big5.force_encoding('Big5') - end - @request.session[:user_id] = 3 - post :create, :project_id => 1, - :time_entry => {:comments => str_utf8, - # Not the default activity - :activity_id => '11', - :issue_id => '', - :spent_on => '2011-11-10', - :hours => '7.3'} - assert_redirected_to :action => 'index', :project_id => 'ecookbook' - - t = TimeEntry.find_by_comments(str_utf8) - assert_not_nil t - assert_equal 11, t.activity_id - assert_equal 7.3, t.hours - assert_equal 3, t.user_id - - get :index, :project_id => 1, :format => 'csv', - :from => '2011-11-10', :to => '2011-11-10' - assert_response :success - assert_equal 'text/csv; header=present', @response.content_type - ar = @response.body.chomp.split("\n") - s1 = "\xa4\xe9\xb4\xc1" - if str_utf8.respond_to?(:force_encoding) - s1.force_encoding('Big5') - end - assert ar[0].include?(s1) - assert ar[1].include?(str_big5) - end - - def test_csv_cannot_convert_should_be_replaced_big_5 - user = User.find_by_id(3) - user.language = "zh-TW" - assert user.save - str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85" - if str_utf8.respond_to?(:force_encoding) - str_utf8.force_encoding('UTF-8') - end - @request.session[:user_id] = 3 - post :create, :project_id => 1, - :time_entry => {:comments => str_utf8, - # Not the default activity - :activity_id => '11', - :issue_id => '', - :spent_on => '2011-11-10', - :hours => '7.3'} - assert_redirected_to :action => 'index', :project_id => 'ecookbook' - - t = TimeEntry.find_by_comments(str_utf8) - assert_not_nil t - assert_equal 11, t.activity_id - assert_equal 7.3, t.hours - assert_equal 3, t.user_id - - get :index, :project_id => 1, :format => 'csv', - :from => '2011-11-10', :to => '2011-11-10' - assert_response :success - assert_equal 'text/csv; header=present', @response.content_type - ar = @response.body.chomp.split("\n") - s1 = "\xa4\xe9\xb4\xc1" - if str_utf8.respond_to?(:force_encoding) - s1.force_encoding('Big5') - end - assert ar[0].include?(s1) - s2 = ar[1].split(",")[8] - if s2.respond_to?(:force_encoding) - s3 = "\xa5H?" - s3.force_encoding('Big5') - assert_equal s3, s2 - elsif RUBY_PLATFORM == 'java' - assert_equal "??", s2 - else - assert_equal "\xa5H???", s2 - end - end - - def test_csv_tw - with_settings :default_language => "zh-TW" do - str1 = "test_csv_tw" - user = User.find_by_id(3) - te1 = TimeEntry.create(:spent_on => '2011-11-10', - :hours => 999.9, - :project => Project.find(1), - :user => user, - :activity => TimeEntryActivity.find_by_name('Design'), - :comments => str1) - te2 = TimeEntry.find_by_comments(str1) - assert_not_nil te2 - assert_equal 999.9, te2.hours - assert_equal 3, te2.user_id - - get :index, :project_id => 1, :format => 'csv', - :from => '2011-11-10', :to => '2011-11-10' - assert_response :success - assert_equal 'text/csv; header=present', @response.content_type - - ar = @response.body.chomp.split("\n") - s2 = ar[1].split(",")[7] - assert_equal '999.9', s2 - - str_tw = "Traditional Chinese (\xe7\xb9\x81\xe9\xab\x94\xe4\xb8\xad\xe6\x96\x87)" - if str_tw.respond_to?(:force_encoding) - str_tw.force_encoding('UTF-8') - end - assert_equal str_tw, l(:general_lang_name) - assert_equal ',', l(:general_csv_separator) - assert_equal '.', l(:general_csv_decimal_separator) - end - end - - def test_csv_fr - with_settings :default_language => "fr" do - str1 = "test_csv_fr" - user = User.find_by_id(3) - te1 = TimeEntry.create(:spent_on => '2011-11-10', - :hours => 999.9, - :project => Project.find(1), - :user => user, - :activity => TimeEntryActivity.find_by_name('Design'), - :comments => str1) - te2 = TimeEntry.find_by_comments(str1) - assert_not_nil te2 - assert_equal 999.9, te2.hours - assert_equal 3, te2.user_id - - get :index, :project_id => 1, :format => 'csv', - :from => '2011-11-10', :to => '2011-11-10' - assert_response :success - assert_equal 'text/csv; header=present', @response.content_type - - ar = @response.body.chomp.split("\n") - s2 = ar[1].split(";")[7] - assert_equal '999,9', s2 - - str_fr = "Fran\xc3\xa7ais" - if str_fr.respond_to?(:force_encoding) - str_fr.force_encoding('UTF-8') - end - assert_equal str_fr, l(:general_lang_name) - assert_equal ';', l(:general_csv_separator) - assert_equal ',', l(:general_csv_decimal_separator) - end + assert_equal 'text/csv; header=present', response.content_type end end