profile_test.rb
1.68 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
require File.dirname(__FILE__) + '/../test_helper'
class ProfileTest < Test::Unit::TestCase
fixtures :profiles, :virtual_communities, :users
def test_identifier_validation
p = Profile.new
p.valid?
assert p.errors.invalid?(:identifier)
p.identifier = 'with space'
p.valid?
assert p.errors.invalid?(:identifier)
p.identifier = 'áéíóú'
p.valid?
assert p.errors.invalid?(:identifier)
p.identifier = 'rightformat2007'
p.valid?
assert ! p.errors.invalid?(:identifier)
p.identifier = 'rightformat'
p.valid?
assert ! p.errors.invalid?(:identifier)
p.identifier = 'right_format'
p.valid?
assert ! p.errors.invalid?(:identifier)
end
def test_has_domains
p = Profile.new
assert_kind_of Array, p.domains
end
def test_belongs_to_virtual_community_and_has_default
p = Profile.new
assert_kind_of VirtualCommunity, p.virtual_community
end
def test_can_have_user
p = profiles(:johndoe)
assert_kind_of User, p.user
end
def test_may_have_no_user
p = profiles(:john_and_joe)
assert_nil p.user
assert p.valid?
end
def test_only_one_profile_per_user
p1 = profiles(:johndoe)
assert_equal users(:johndoe), p1.user
p2 = Profile.new
p2.user = users(:johndoe)
assert !p2.valid?
assert p2.errors.invalid?(:user_id)
end
def test_several_profiles_without_user
p1 = profiles(:john_and_joe)
assert p1.valid?
assert_nil p1.user
p2 = Profile.new
assert !p2.valid?
assert !p2.errors.invalid?(:user_id)
end
def test_cannot_rename
p1 = profiles(:johndoe)
assert_raise ArgumentError do
p1.identifier = 'bli'
end
end
end