person_test.rb
3.2 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
require File.dirname(__FILE__) + '/../test_helper'
class PersonTest < Test::Unit::TestCase
fixtures :profiles, :users, :comatose_pages
def test_person_must_come_form_the_cration_of_an_user
p = Person.new(:name => 'John', :identifier => 'john')
assert !p.valid?
p.user = User.create(:login => 'john', :email => 'john@doe.org', :password => 'dhoe', :password_confirmation => 'dhoe')
assert !p.valid?
p = User.create(:login => 'johnz', :email => 'johnz@doe.org', :password => 'dhoe', :password_confirmation => 'dhoe').person
assert p.valid?
end
def test_can_associate_to_a_profile
pr = Profile.new(:identifier => 'mytestprofile', :name => 'My test profile')
assert pr.save
pe = User.create(:login => 'person', :email => 'person@test.net', :password => 'dhoe', :password_confirmation => 'dhoe').person
assert pe.save
member_role = Role.create(:name => 'member')
pr.affiliate(pe, member_role)
assert pe.memberships.include?(pr)
end
def test_can_belongs_to_an_enterprise
e = Enterprise.new(:identifier => 'enterprise', :name => 'enterprise')
assert e.save
p = User.create(:login => 'person', :email => 'person@test.net', :password => 'dhoe', :password_confirmation => 'dhoe').person
assert p.save
member_role = Role.create(:name => 'member')
e.affiliate(p, member_role)
assert p.memberships.include?(e)
end
def test_can_have_user
u = User.new(:login => 'john', :email => 'john@doe.org', :password => 'dhoe', :password_confirmation => 'dhoe')
p = Person.new(:name => 'John', :identifier => 'john')
u.person = p
assert u.save
assert_kind_of User, p.user
assert_equal 'John', u.person.name
end
def test_only_one_person_per_user
u = User.new(:login => 'john', :email => 'john@doe.org', :password => 'dhoe', :password_confirmation => 'dhoe')
assert u.save
p1 = u.person
assert_equal u, p1.user
p2 = Person.new
p2.user = u
assert !p2.valid?
assert p2.errors.invalid?(:user_id)
end
should "have person info" do
p = Person.new
assert_kind_of PersonInfo, p.person_info
end
should 'return person_info as info' do
p = Person.new
assert_equal p.person_info, p.info
end
should 'change the roles of the user' do
p = User.create(:login => 'jonh', :email => 'john@doe.org', :password => 'dhoe', :password_confirmation => 'dhoe').person
e = Enterprise.create(:identifier => 'enter', :name => 'Enter')
r1 = Role.create(:name => 'associate')
assert e.affiliate(p, r1)
r2 = Role.create(:name => 'partner')
assert p.define_roles([r2], e)
p.reload
assert p.role_assignments.any? {|ra| ra.role == r2}
assert !p.role_assignments.any? {|ra| ra.role == r1}
end
should 'report that the user has the permission' do
p = User.create(:login => 'jonh', :email => 'john@doe.org', :password => 'dhoe', :password_confirmation => 'dhoe').person
r = Role.create(:name => 'associate', :permissions => ['edit_profile'])
e = Enterprise.create(:identifier => 'enterpri', :name => 'Enterpri')
assert e.affiliate(p, r)
assert p.reload
assert e.reload
assert p.has_permission?('edit_profile', e)
assert !p.has_permission?('destroy_profile', e)
end
end