summaryrefslogtreecommitdiffstats
path: root/test/unit/principal_test.rb
diff options
context:
space:
mode:
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)