diff options
author | Eric Davis <edavis@littlestreamsoftware.com> | 2010-09-10 19:44:45 +0000 |
---|---|---|
committer | Eric Davis <edavis@littlestreamsoftware.com> | 2010-09-10 19:44:45 +0000 |
commit | 41f8d043eb29452ff11baf5e5286cd907cda742e (patch) | |
tree | 6d66e1b4d7ea8f8c312ce3ab551d9e7704d7164a /test | |
parent | 109b42f4828c0966e771809afcfd99d545af3ca0 (diff) | |
download | redmine-41f8d043eb29452ff11baf5e5286cd907cda742e.tar.gz redmine-41f8d043eb29452ff11baf5e5286cd907cda742e.zip |
Added a "Member of Role" to the issues filters. #5869
This filter will check an issue's assigned to field for users who have
(or don't have) a specific Role(s).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4078 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test')
-rw-r--r-- | test/object_daddy_helpers.rb | 5 | ||||
-rw-r--r-- | test/unit/query_test.rb | 68 |
2 files changed, 72 insertions, 1 deletions
diff --git a/test/object_daddy_helpers.rb b/test/object_daddy_helpers.rb index 7b144b18f..c94ada229 100644 --- a/test/object_daddy_helpers.rb +++ b/test/object_daddy_helpers.rb @@ -13,6 +13,11 @@ module ObjectDaddyHelpers User.spawn(attributes) end + def User.add_to_project(user, project, roles) + roles = [roles] unless roles.is_a?(Array) + Member.generate!(:principal => user, :project => project, :roles => roles) + end + # Generate the default Query def Query.generate_default!(attributes={}) query = Query.spawn(attributes) diff --git a/test/unit/query_test.rb b/test/unit/query_test.rb index acab56ffd..f737b2f0c 100644 --- a/test/unit/query_test.rb +++ b/test/unit/query_test.rb @@ -404,7 +404,29 @@ class QueryTest < ActiveSupport::TestCase end end - + + context "'assigned_to_role' filter" do + should "be present" do + assert @query.available_filters.keys.include?("assigned_to_role") + end + + should "be an optional list" do + assert_equal :list_optional, @query.available_filters["assigned_to_role"][:type] + end + + should "have a list of the Roles as values" do + assert @query.available_filters["assigned_to_role"][:values].include?(['Manager',1]) + assert @query.available_filters["assigned_to_role"][:values].include?(['Developer',2]) + assert @query.available_filters["assigned_to_role"][:values].include?(['Reporter',3]) + end + + should "not include the built in Roles as values" do + assert ! @query.available_filters["assigned_to_role"][:values].include?(['Non member',4]) + assert ! @query.available_filters["assigned_to_role"][:values].include?(['Anonymous',5]) + end + + end + end context "#statement" do @@ -453,6 +475,50 @@ class QueryTest < ActiveSupport::TestCase end end + + context "with 'assigned_to_role' filter" do + setup do + # No fixtures + MemberRole.delete_all + Member.delete_all + Role.delete_all + + @manager_role = Role.generate!(:name => 'Manager') + @developer_role = Role.generate!(:name => 'Developer') + + @project = Project.generate! + @manager = User.generate! + @developer = User.generate! + @boss = User.generate! + User.add_to_project(@manager, @project, @manager_role) + User.add_to_project(@developer, @project, @developer_role) + User.add_to_project(@boss, @project, [@manager_role, @developer_role]) + end + + should "search assigned to for users with the Role" do + @query = Query.new(:name => '_') + @query.add_filter('assigned_to_role', '=', [@manager_role.id.to_s]) + + assert_query_statement_includes @query, "#{Issue.table_name}.assigned_to_id IN ('#{@manager.id}','#{@boss.id}')" + assert_find_issues_with_query_is_successful @query + end + + should "search assigned to for users not assigned to any Role (none)" do + @query = Query.new(:name => '_') + @query.add_filter('assigned_to_role', '!*', ['']) + + assert_query_statement_includes @query, "#{Issue.table_name}.assigned_to_id IS NULL OR #{Issue.table_name}.assigned_to_id NOT IN ('#{@manager.id}','#{@developer.id}','#{@boss.id}')" + assert_find_issues_with_query_is_successful @query + end + + should "search assigned to for users assigned to any Role (all)" do + @query = Query.new(:name => '_') + @query.add_filter('assigned_to_role', '*', ['']) + + assert_query_statement_includes @query, "#{Issue.table_name}.assigned_to_id IN ('#{@manager.id}','#{@developer.id}','#{@boss.id}')" + assert_find_issues_with_query_is_successful @query + end + end end end |