diff options
author | Go MAEDA <maeda@farend.jp> | 2024-08-16 02:05:25 +0000 |
---|---|---|
committer | Go MAEDA <maeda@farend.jp> | 2024-08-16 02:05:25 +0000 |
commit | 65597ec1cfca87f3f0667d6e2de21621e16e2cb0 (patch) | |
tree | d325b06b21ceb21461a75fa496208b6ac1decc01 /test/unit/time_entry_query_test.rb | |
parent | d7db0e479017e9272fb7d3f5affc0a08a39f9a41 (diff) | |
download | redmine-65597ec1cfca87f3f0667d6e2de21621e16e2cb0.tar.gz redmine-65597ec1cfca87f3f0667d6e2de21621e16e2cb0.zip |
Add filters for "User's group" and "User's role" to Spent time list (#41053).
Patch by Takenori TAKAKI (user:takenory).
git-svn-id: https://svn.redmine.org/redmine/trunk@22958 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/unit/time_entry_query_test.rb')
-rw-r--r-- | test/unit/time_entry_query_test.rb | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/test/unit/time_entry_query_test.rb b/test/unit/time_entry_query_test.rb index 2ecca1231..77e125c80 100644 --- a/test/unit/time_entry_query_test.rb +++ b/test/unit/time_entry_query_test.rb @@ -136,6 +136,69 @@ class TimeEntryQueryTest < ActiveSupport::TestCase assert !query.available_filters.has_key?('project.status') end + def test_user_group_filter_should_consider_spacified_groups_time_entries + Group.find(10).users << User.find(2) + Group.find(11).users << User.find(3) + + TimeEntry.delete_all + t1 = TimeEntry.generate!(:hours => 1.0, :user_id => 2) + t2 = TimeEntry.generate!(:hours => 2.0, :user_id => 2) + t3 = TimeEntry.generate!(:hours => 4.0, :user_id => 3) + + query = TimeEntryQuery.new(:name => '_') + result = query.base_scope.to_a + assert result.include?(t1) + assert result.include?(t2) + assert result.include?(t3) + assert_equal 7.0, query.results_scope.sum(:hours) + + query.add_filter('user.group', '=', ['10']) + result = query.base_scope.to_a + assert result.include?(t1) + assert result.include?(t2) + assert_not result.include?(t3) + assert_equal 3.0, query.results_scope.sum(:hours) + + query.add_filter('user.group', '=', ['10', '11']) + result = query.base_scope.to_a + assert result.include?(t1) + assert result.include?(t2) + assert result.include?(t3) + assert_equal 7.0, query.results_scope.sum(:hours) + end + + def test_user_role_filter_should_consider_spacified_roles_time_entries + project = Project.find(1) + project.members << Member.new(:user_id => 2, :roles => [Role.find(1)]) + project.members << Member.new(:user_id => 3, :roles => [Role.find(2)]) + + TimeEntry.delete_all + t1 = TimeEntry.generate!(:project => project, :hours => 1.0, :user_id => 2) + t2 = TimeEntry.generate!(:project => project, :hours => 2.0, :user_id => 2) + t3 = TimeEntry.generate!(:project => project, :hours => 4.0, :user_id => 3) + + query = TimeEntryQuery.new(:project => project, :name => '_') + result = query.base_scope.to_a + assert result.include?(t1) + assert result.include?(t2) + assert result.include?(t3) + assert_equal 7.0, query.results_scope.sum(:hours) + + query.add_filter('user.role', '=', ['1']) + result = query.base_scope.to_a + assert result.include?(t1) + assert result.include?(t2) + assert_not result.include?(t3) + assert_equal 3.0, query.results_scope.sum(:hours) + + query.add_filter('user.role', '=', ['1', '2']) + result = query.base_scope.to_a + assert result.include?(t1) + assert result.include?(t2) + assert result.include?(t3) + assert_equal 7.0, query.results_scope.sum(:hours) + end + def test_results_scope_should_be_in_the_same_order_when_paginating 4.times {TimeEntry.generate!} q = TimeEntryQuery.new |