summaryrefslogtreecommitdiff
path: root/test/unit/user_group_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/unit/user_group_test.rb')
-rw-r--r--test/unit/user_group_test.rb38
1 files changed, 38 insertions, 0 deletions
diff --git a/test/unit/user_group_test.rb b/test/unit/user_group_test.rb
new file mode 100644
index 0000000..5e815a8
--- /dev/null
+++ b/test/unit/user_group_test.rb
@@ -0,0 +1,38 @@
+require 'test_helper'
+
+class UserGroupTest < ActiveSupport::TestCase
+ def test_should_have_a_valid_factory
+ assert Factory.build(:user_group).valid?
+ end
+
+ def test_should_have_unique_name_on_same_tenant
+ tenant1 = Factory.create(:tenant)
+ tenant2 = Factory.create(:tenant)
+ group = Factory.create(:user_group, :tenant_id => tenant1.id)
+ assert !Factory.build(:user_group, :name => group.name, :tenant_id => tenant1.id).valid?
+ assert Factory.build(:user_group, :name => group.name, :tenant_id => tenant2.id).valid?
+ assert Factory.build(:user_group, :name => "different_#{group.name}", :tenant_id => tenant1.id).valid?
+ end
+
+ test "user_group_membership only available for tenant_memberships" do
+ good_tenant = Factory.create(:tenant)
+ evil_tenant = Factory.create(:tenant)
+
+ user = Factory.create(:user)
+ good_tenant.tenant_memberships.create(:user_id => user.id)
+
+ good_user_group = good_tenant.user_groups.create(:name => 'Example')
+ evil_user_group = evil_tenant.user_groups.create(:name => 'Example')
+
+ # Check the basics
+ assert_equal 1, good_tenant.user_groups.count
+ assert_equal 1, evil_tenant.user_groups.count
+ assert_equal 1, good_tenant.users.count
+ assert_equal 0, evil_tenant.users.count
+
+ # Check if the user can become a member
+ assert good_user_group.user_group_memberships.build(:user_id => user.id).valid?
+ assert !evil_user_group.user_group_memberships.build(:user_id => user.id).valid?
+ end
+
+end