From e6d63a4e0d3be4000d7067ef10f3db2e824a90ce Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sun, 24 Feb 2013 09:22:41 +0000 Subject: [PATCH] Merged r11459 from trunk. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/2.3-stable@11460 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- lib/redmine/helpers/time_report.rb | 13 ++++--- .../time_entry_reports_controller_test.rb | 34 +++++++++++++------ 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/lib/redmine/helpers/time_report.rb b/lib/redmine/helpers/time_report.rb index 4798fe6e6..870452758 100644 --- a/lib/redmine/helpers/time_report.rb +++ b/lib/redmine/helpers/time_report.rb @@ -127,13 +127,16 @@ module Redmine :label => :label_issue} } - # Add list and boolean custom fields as available criteria - custom_fields = (@project.nil? ? IssueCustomField.for_all : @project.all_issue_custom_fields) - # Add list and boolean time entry custom fields - custom_fields += TimeEntryCustomField.all - # Add list and boolean time entry activity custom fields + # Add time entry custom fields + custom_fields = TimeEntryCustomField.all + # Add project custom fields + custom_fields += ProjectCustomField.all + # Add issue custom fields + custom_fields += (@project.nil? ? IssueCustomField.for_all : @project.all_issue_custom_fields) + # Add time entry activity custom fields custom_fields += TimeEntryActivityCustomField.all + # Add list and boolean custom fields as available criteria custom_fields.select {|cf| %w(list bool).include? cf.field_format }.each do |cf| @available_criteria["cf_#{cf.id}"] = {:sql => "#{cf.join_alias}.value", :joins => cf.join_for_order_statement, diff --git a/test/functional/time_entry_reports_controller_test.rb b/test/functional/time_entry_reports_controller_test.rb index 0e1fe7c84..759d5d19b 100644 --- a/test/functional/time_entry_reports_controller_test.rb +++ b/test/functional/time_entry_reports_controller_test.rb @@ -125,22 +125,36 @@ class TimeEntryReportsControllerTest < ActionController::TestCase :attributes => {:action => "/projects/ecookbook/issues/1/time_entries/report", :id => 'query_form'} end - def test_report_custom_field_criteria - get :report, :project_id => 1, :criteria => ['project', 'cf_1', 'cf_7'] + def test_report_should_propose_association_custom_fields + get :report + assert_response :success + assert_template 'report' + + assert_select 'select[name=?]', 'criteria[]' do + assert_select 'option[value=cf_1]', {:text => 'Database'}, 'Issue custom field not found' + assert_select 'option[value=cf_3]', {:text => 'Development status'}, 'Project custom field not found' + assert_select 'option[value=cf_7]', {:text => 'Billable'}, 'TimeEntryActivity custom field not found' + end + end + + def test_report_with_association_custom_fields + get :report, :criteria => ['cf_1', 'cf_3', 'cf_7'] assert_response :success assert_template 'report' assert_not_nil assigns(:report) assert_equal 3, assigns(:report).criteria.size assert_equal "162.90", "%.2f" % assigns(:report).total_hours - # Custom field column - assert_tag :tag => 'th', :content => 'Database' + + # Custom fields columns + assert_select 'th', :text => 'Database' + assert_select 'th', :text => 'Development status' + assert_select 'th', :text => 'Billable' + # Custom field row - assert_tag :tag => 'td', :content => 'MySQL', - :sibling => { :tag => 'td', :attributes => { :class => 'hours' }, - :child => { :tag => 'span', :attributes => { :class => 'hours hours-int' }, - :content => '1' }} - # Second custom field column - assert_tag :tag => 'th', :content => 'Billable' + assert_select 'tr' do + assert_select 'td', :text => 'MySQL' + assert_select 'td.hours', :text => '1.00' + end end def test_report_one_criteria_no_result