diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2013-07-11 17:45:10 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2013-07-11 17:45:10 +0000 |
commit | 888c3581eb0fbfc5ede87a24f7f03bfa4f7d810b (patch) | |
tree | 17bb48e3b640635b2fa62b85e2b10ccaf5b4f65c /test/unit | |
parent | 4545b906b4c58e2bd1d201fd18a49249aa571dfc (diff) | |
download | redmine-888c3581eb0fbfc5ede87a24f7f03bfa4f7d810b.tar.gz redmine-888c3581eb0fbfc5ede87a24f7f03bfa4f7d810b.zip |
Role based custom queries (#1019).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11994 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/unit')
-rw-r--r-- | test/unit/query_test.rb | 66 | ||||
-rw-r--r-- | test/unit/user_test.rb | 4 |
2 files changed, 68 insertions, 2 deletions
diff --git a/test/unit/query_test.rb b/test/unit/query_test.rb index 59639384f..15f1cf21c 100644 --- a/test/unit/query_test.rb +++ b/test/unit/query_test.rb @@ -28,6 +28,24 @@ class QueryTest < ActiveSupport::TestCase :projects_trackers, :custom_fields_trackers + def test_query_with_roles_visibility_should_validate_roles + set_language_if_valid 'en' + query = IssueQuery.new(:name => 'Query', :visibility => IssueQuery::VISIBILITY_ROLES) + assert !query.save + assert_include "Roles can't be blank", query.errors.full_messages + query.role_ids = [1, 2] + assert query.save + end + + def test_changing_roles_visibility_should_clear_roles + query = IssueQuery.create!(:name => 'Query', :visibility => IssueQuery::VISIBILITY_ROLES, :role_ids => [1, 2]) + assert_equal 2, query.roles.count + + query.visibility = IssueQuery::VISIBILITY_PUBLIC + query.save! + assert_equal 0, query.roles.count + end + def test_available_filters_should_be_ordered set_language_if_valid 'en' query = IssueQuery.new @@ -1089,6 +1107,54 @@ class QueryTest < ActiveSupport::TestCase assert !query_ids.include?(7), 'public query on private project was visible' end + def test_query_with_public_visibility_should_be_visible_to_anyone + q = IssueQuery.create!(:name => 'Query', :visibility => IssueQuery::VISIBILITY_PUBLIC) + + assert q.visible?(User.anonymous) + assert IssueQuery.visible(User.anonymous).find_by_id(q.id) + + assert q.visible?(User.find(7)) + assert IssueQuery.visible(User.find(7)).find_by_id(q.id) + + assert q.visible?(User.find(2)) + assert IssueQuery.visible(User.find(2)).find_by_id(q.id) + + assert q.visible?(User.find(1)) + assert IssueQuery.visible(User.find(1)).find_by_id(q.id) + end + + def test_query_with_roles_visibility_should_be_visible_to_user_with_role + q = IssueQuery.create!(:name => 'Query', :visibility => IssueQuery::VISIBILITY_ROLES, :role_ids => [1,2]) + + assert !q.visible?(User.anonymous) + assert_nil IssueQuery.visible(User.anonymous).find_by_id(q.id) + + assert !q.visible?(User.find(7)) + assert_nil IssueQuery.visible(User.find(7)).find_by_id(q.id) + + assert q.visible?(User.find(2)) + assert IssueQuery.visible(User.find(2)).find_by_id(q.id) + + assert q.visible?(User.find(1)) + assert IssueQuery.visible(User.find(1)).find_by_id(q.id) + end + + def test_query_with_private_visibility_should_be_visible_to_owner + q = IssueQuery.create!(:name => 'Query', :visibility => IssueQuery::VISIBILITY_PRIVATE, :user => User.find(7)) + + assert !q.visible?(User.anonymous) + assert_nil IssueQuery.visible(User.anonymous).find_by_id(q.id) + + assert q.visible?(User.find(7)) + assert IssueQuery.visible(User.find(7)).find_by_id(q.id) + + assert !q.visible?(User.find(2)) + assert_nil IssueQuery.visible(User.find(2)).find_by_id(q.id) + + assert q.visible?(User.find(1)) + assert_nil IssueQuery.visible(User.find(1)).find_by_id(q.id) + end + test "#available_filters should include users of visible projects in cross-project view" do users = IssueQuery.new.available_filters["assigned_to_id"] assert_not_nil users diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index 4594d8e1a..52a7d64b7 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -291,7 +291,7 @@ class UserTest < ActiveSupport::TestCase end def test_destroy_should_delete_private_queries - query = Query.new(:name => 'foo', :is_public => false) + query = Query.new(:name => 'foo', :visibility => Query::VISIBILITY_PRIVATE) query.project_id = 1 query.user_id = 2 query.save! @@ -302,7 +302,7 @@ class UserTest < ActiveSupport::TestCase end def test_destroy_should_update_public_queries - query = Query.new(:name => 'foo', :is_public => true) + query = Query.new(:name => 'foo', :visibility => Query::VISIBILITY_PUBLIC) query.project_id = 1 query.user_id = 2 query.save! |