summaryrefslogtreecommitdiffstats
path: root/test/unit/principal_test.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2014-11-11 13:08:52 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2014-11-11 13:08:52 +0000
commitbdd3ccf8e52c69d2b6e16e7230a1b8f9a6c69e60 (patch)
tree1571b147765d42bccab602cdd9a79499829de612 /test/unit/principal_test.rb
parent140ca9532c1c12b7ff710c076c6985dce18500e4 (diff)
downloadredmine-bdd3ccf8e52c69d2b6e16e7230a1b8f9a6c69e60.tar.gz
redmine-bdd3ccf8e52c69d2b6e16e7230a1b8f9a6c69e60.zip
Adds a role setting for controlling visibility of users: all or members of visible projects (#11724).
git-svn-id: http://svn.redmine.org/redmine/trunk@13584 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/unit/principal_test.rb')
-rw-r--r--test/unit/principal_test.rb23
1 files changed, 22 insertions, 1 deletions
diff --git a/test/unit/principal_test.rb b/test/unit/principal_test.rb
index 3b599c373..4e2dd4f21 100644
--- a/test/unit/principal_test.rb
+++ b/test/unit/principal_test.rb
@@ -20,7 +20,7 @@
require File.expand_path('../../test_helper', __FILE__)
class PrincipalTest < ActiveSupport::TestCase
- fixtures :users, :projects, :members, :member_roles
+ fixtures :users, :projects, :members, :member_roles, :roles
def test_active_scope_should_return_groups_and_active_users
result = Principal.active.to_a
@@ -30,6 +30,27 @@ class PrincipalTest < ActiveSupport::TestCase
assert_nil result.detect {|p| p.is_a?(AnonymousUser)}
end
+ def test_visible_scope_for_admin_should_return_all_principals
+ admin = User.generate! {|u| u.admin = true}
+ assert_equal Principal.count, Principal.visible(admin).count
+ end
+
+ def test_visible_scope_for_user_with_members_of_visible_projects_visibility_should_return_active_principals
+ Role.non_member.update! :users_visibility => 'all'
+ user = User.generate!
+
+ expected = Principal.active
+ assert_equal expected.map(&:id).sort, Principal.visible(user).pluck(:id).sort
+ end
+
+ def test_visible_scope_for_user_with_members_of_visible_projects_visibility_should_return_members_of_visible_projects_and_self
+ Role.non_member.update! :users_visibility => 'members_of_visible_projects'
+ user = User.generate!
+
+ expected = Project.visible(user).map(&:member_principals).flatten.map(&:principal).uniq << user
+ assert_equal expected.map(&:id).sort, Principal.visible(user).pluck(:id).sort
+ end
+
def test_member_of_scope_should_return_the_union_of_all_members
projects = Project.find([1])
assert_equal [3, 2], Principal.member_of(projects).sort.map(&:id)