summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2015-10-09 09:02:11 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2015-10-09 09:02:11 +0000
commit498a429a41bc47fc7e3980926901cc60863afe9a (patch)
treeb72a844dd383e35a87562d6278134737a8f660ee /test
parent3a3fe668c77cdb3266bfd1b067a30a1c09713763 (diff)
downloadredmine-498a429a41bc47fc7e3980926901cc60863afe9a.tar.gz
redmine-498a429a41bc47fc7e3980926901cc60863afe9a.zip
Display totals for each group on grouped queries (#1561).
git-svn-id: http://svn.redmine.org/redmine/trunk@14665 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test')
-rw-r--r--test/functional/issues_controller_test.rb24
-rw-r--r--test/unit/query_test.rb41
2 files changed, 64 insertions, 1 deletions
diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb
index 18c82aef1..158ba4316 100644
--- a/test/functional/issues_controller_test.rb
+++ b/test/functional/issues_controller_test.rb
@@ -953,10 +953,32 @@ class IssuesControllerTest < ActionController::TestCase
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 '.total-for-estimated-hours span.value', :text => '6.60'
assert_select 'input[type=checkbox][name=?][value=estimated_hours][checked=checked]', 't[]'
end
+ def test_index_with_grouped_query_and_estimated_hours_total
+ Issue.delete_all
+ Issue.generate!(:estimated_hours => 5.5, :category_id => 1)
+ Issue.generate!(:estimated_hours => 2.3, :category_id => 1)
+ Issue.generate!(:estimated_hours => 1.1, :category_id => 2)
+ Issue.generate!(:estimated_hours => 4.6)
+
+ get :index, :t => %w(estimated_hours), :group_by => 'category'
+ assert_response :success
+ assert_select '.query-totals'
+ assert_select '.query-totals .total-for-estimated-hours span.value', :text => '13.50'
+ assert_select 'tr.group', :text => /Printing/ do
+ assert_select '.total-for-estimated-hours span.value', :text => '7.80'
+ end
+ assert_select 'tr.group', :text => /Recipes/ do
+ assert_select '.total-for-estimated-hours span.value', :text => '1.10'
+ end
+ assert_select 'tr.group', :text => /blank/ do
+ assert_select '.total-for-estimated-hours span.value', :text => '4.60'
+ end
+ 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')
diff --git a/test/unit/query_test.rb b/test/unit/query_test.rb
index b69bec740..679fc772d 100644
--- a/test/unit/query_test.rb
+++ b/test/unit/query_test.rb
@@ -1183,6 +1183,19 @@ class QueryTest < ActiveSupport::TestCase
assert_equal 6.6, q.total_for(:estimated_hours)
end
+ def test_total_by_group_for_estimated_hours
+ Issue.delete_all
+ Issue.generate!(:estimated_hours => 5.5, :assigned_to_id => 2)
+ Issue.generate!(:estimated_hours => 1.1, :assigned_to_id => 3)
+ Issue.generate!(:estimated_hours => 3.5)
+
+ q = IssueQuery.new(:group_by => 'assigned_to')
+ assert_equal(
+ {nil => 3.5, User.find(2) => 5.5, User.find(3) => 1.1},
+ q.total_by_group_for(:estimated_hours)
+ )
+ end
+
def test_total_for_spent_hours
TimeEntry.delete_all
TimeEntry.generate!(:hours => 5.5)
@@ -1192,6 +1205,20 @@ class QueryTest < ActiveSupport::TestCase
assert_equal 6.6, q.total_for(:spent_hours)
end
+ def test_total_by_group_for_spent_hours
+ TimeEntry.delete_all
+ TimeEntry.generate!(:hours => 5.5, :issue_id => 1)
+ TimeEntry.generate!(:hours => 1.1, :issue_id => 2)
+ Issue.where(:id => 1).update_all(:assigned_to_id => 2)
+ Issue.where(:id => 2).update_all(:assigned_to_id => 3)
+
+ q = IssueQuery.new(:group_by => 'assigned_to')
+ assert_equal(
+ {User.find(2) => 5.5, User.find(3) => 1.1},
+ q.total_by_group_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')
@@ -1202,6 +1229,20 @@ class QueryTest < ActiveSupport::TestCase
assert_equal 9, q.total_for("cf_#{field.id}")
end
+ def test_total_by_group_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')
+ Issue.where(:id => 1).update_all(:assigned_to_id => 2)
+ Issue.where(:id => 2).update_all(:assigned_to_id => 3)
+
+ q = IssueQuery.new(:group_by => 'assigned_to')
+ assert_equal(
+ {User.find(2) => 2, User.find(3) => 7},
+ q.total_by_group_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')