summaryrefslogtreecommitdiff
path: root/test/unit/user_group_membership_test.rb
blob: 34a577cd433cff9dccbfb562d17ea6760b083703 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
require 'test_helper'

class UserGroupMembershipTest < ActiveSupport::TestCase
  def test_should_have_a_valid_factory
    assert FactoryGirl.build(:user_group_membership).valid?
  end
  def test_should_have_unique_members_in_each_group
    group1 = FactoryGirl.create(:user_group)
    group2 = FactoryGirl.create(:user_group)
    user1 = FactoryGirl.create(:user)
    user2 = FactoryGirl.create(:user)
    member = FactoryGirl.create(
                            :user_group_membership,
                            :user_id => user1.id,
                            :user_group_id => group1.id
                            )
    assert !FactoryGirl.build(
                          :user_group_membership,
                          :user_id => user1.id,
                          :user_group_id => group1.id
                            ).valid?
    assert FactoryGirl.build(
                          :user_group_membership,
                          :user_id => user1.id,
                          :user_group_id => group2.id
                            ).valid?
    assert FactoryGirl.build(
                          :user_group_membership,
                          :user_id => user2.id,
                          :user_group_id => group1.id
                            ).valid?
  end
  
  def test_that_the_initial_state_should_be_active
    @user_group_membership = FactoryGirl.create(:user_group_membership)
    assert_equal 'active', @user_group_membership.state
    assert @user_group_membership.active?
  end
end