diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2015-10-04 19:42:37 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2015-10-04 19:42:37 +0000 |
commit | 446f70f584320aa8da62b72a7116dce298eca07e (patch) | |
tree | 046ec4a3108ccd6af6ec4d70594923610408a329 /test | |
parent | 35a059a756144384888fcc576a72d20b2417e009 (diff) | |
download | redmine-446f70f584320aa8da62b72a7116dce298eca07e.tar.gz redmine-446f70f584320aa8da62b72a7116dce298eca07e.zip |
Adds options to display totals on the issue list (#1561).
Works for estimated hours, spent hours and any numeric custom field.
git-svn-id: http://svn.redmine.org/redmine/trunk@14642 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test')
-rw-r--r-- | test/functional/issues_controller_test.rb | 32 | ||||
-rw-r--r-- | test/unit/query_test.rb | 76 |
2 files changed, 108 insertions, 0 deletions
diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index 432693a56..18c82aef1 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -945,6 +945,38 @@ class IssuesControllerTest < ActionController::TestCase assert_select 'td.parent a[title=?]', parent.subject end + def test_index_with_estimated_hours_total + Issue.delete_all + Issue.generate!(:estimated_hours => 5.5) + Issue.generate!(:estimated_hours => 1.1) + + get :index, :t => %w(estimated_hours) + assert_response :success + assert_select '.query-totals' + assert_select '.total-for-estimated-hours span.value', :text => '6.6' + assert_select 'input[type=checkbox][name=?][value=estimated_hours][checked=checked]', 't[]' + end + + def test_index_with_int_custom_field_total + field = IssueCustomField.generate!(:field_format => 'int', :is_for_all => true) + CustomValue.create!(:customized => Issue.find(1), :custom_field => field, :value => '2') + CustomValue.create!(:customized => Issue.find(2), :custom_field => field, :value => '7') + + get :index, :t => ["cf_#{field.id}"] + assert_response :success + assert_select '.query-totals' + assert_select ".total-for-cf-#{field.id} span.value", :text => '9' + end + + def test_index_totals_should_default_to_settings + with_settings :issue_list_default_totals => ['estimated_hours'] do + get :index + assert_response :success + assert_select '.total-for-estimated-hours span.value' + assert_select '.query-totals>span', 1 + end + end + def test_index_send_html_if_query_is_invalid get :index, :f => ['start_date'], :op => {:start_date => '='} assert_equal 'text/html', @response.content_type diff --git a/test/unit/query_test.rb b/test/unit/query_test.rb index aa45b5beb..b69bec740 100644 --- a/test/unit/query_test.rb +++ b/test/unit/query_test.rb @@ -1136,6 +1136,82 @@ class QueryTest < ActiveSupport::TestCase assert_equal values.sort, values end + def test_set_totalable_names + q = IssueQuery.new + q.totalable_names = ['estimated_hours', :spent_hours, ''] + assert_equal [:estimated_hours, :spent_hours], q.totalable_columns.map(&:name) + end + + def test_totalable_columns_should_default_to_settings + with_settings :issue_list_default_totals => ['estimated_hours'] do + q = IssueQuery.new + assert_equal [:estimated_hours], q.totalable_columns.map(&:name) + end + end + + def test_available_totalable_columns_should_include_estimated_hours + q = IssueQuery.new + assert_include :estimated_hours, q.available_totalable_columns.map(&:name) + end + + def test_available_totalable_columns_should_include_spent_hours + User.current = User.find(1) + + q = IssueQuery.new + assert_include :spent_hours, q.available_totalable_columns.map(&:name) + end + + def test_available_totalable_columns_should_include_int_custom_field + field = IssueCustomField.generate!(:field_format => 'int', :is_for_all => true) + q = IssueQuery.new + assert_include "cf_#{field.id}".to_sym, q.available_totalable_columns.map(&:name) + end + + def test_available_totalable_columns_should_include_float_custom_field + field = IssueCustomField.generate!(:field_format => 'float', :is_for_all => true) + q = IssueQuery.new + assert_include "cf_#{field.id}".to_sym, q.available_totalable_columns.map(&:name) + end + + def test_total_for_estimated_hours + Issue.delete_all + Issue.generate!(:estimated_hours => 5.5) + Issue.generate!(:estimated_hours => 1.1) + Issue.generate! + + q = IssueQuery.new + assert_equal 6.6, q.total_for(:estimated_hours) + end + + def test_total_for_spent_hours + TimeEntry.delete_all + TimeEntry.generate!(:hours => 5.5) + TimeEntry.generate!(:hours => 1.1) + + q = IssueQuery.new + assert_equal 6.6, q.total_for(:spent_hours) + end + + def test_total_for_int_custom_field + field = IssueCustomField.generate!(:field_format => 'int', :is_for_all => true) + CustomValue.create!(:customized => Issue.find(1), :custom_field => field, :value => '2') + CustomValue.create!(:customized => Issue.find(2), :custom_field => field, :value => '7') + CustomValue.create!(:customized => Issue.find(3), :custom_field => field, :value => '') + + q = IssueQuery.new + assert_equal 9, q.total_for("cf_#{field.id}") + end + + def test_total_for_float_custom_field + field = IssueCustomField.generate!(:field_format => 'float', :is_for_all => true) + CustomValue.create!(:customized => Issue.find(1), :custom_field => field, :value => '2.3') + CustomValue.create!(:customized => Issue.find(2), :custom_field => field, :value => '7') + CustomValue.create!(:customized => Issue.find(3), :custom_field => field, :value => '') + + q = IssueQuery.new + assert_equal 9.3, q.total_for("cf_#{field.id}") + end + def test_invalid_query_should_raise_query_statement_invalid_error q = IssueQuery.new assert_raise Query::StatementInvalid do |