mpog_user_test.rb
3.37 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
require File.dirname(__FILE__) + '/../../../../test/test_helper'
class MpogSoftwarePluginUserTest < ActiveSupport::TestCase
should 'not save user whose both email and secondary email are the same' do
user = fast_create(User)
user.email = "test@email.com"
user.secondary_email = "test@email.com"
assert !user.save
end
should 'not save user whose both email and secondary email have already been used' do
user1 = create_default_user
user2 = fast_create(User)
user2.email = "primary@email.com"
user2.secondary_email = "secondary@email.com"
assert !user2.save
end
should 'not save user whose email has already been used' do
user1 = create_default_user
user2 = fast_create(User)
user2.email = "primary@email.com"
user2.secondary_email = "noosfero@email.com"
assert !user2.save
end
should 'not save user whose email has already been used in another users secondary email' do
user1 = create_default_user
user2 = fast_create(User)
user2.login = "another-login"
user2.email = "secondary@email.com"
user2.secondary_email = "noosfero@email.com"
assert !user2.save
end
should 'not save user whose secondary email has already been used in another users email' do
user1 = create_default_user
user2 = fast_create(User)
user2.login = "another-login"
user2.email = "noosfero@email.com"
user2.secondary_email = "primary@email.com"
assert !user2.save
end
should 'not save user whose secondary email has already been used in another users secondary email' do
user1 = create_default_user
user2 = fast_create(User)
user2.login = "another-login"
user2.email = "noosfero@email.com"
user2.secondary_email = "secondary@email.com"
assert !user2.save
end
should 'not save user whose secondary email is in the wrong format' do
user = fast_create(User)
user.email = "test@email.com"
user.secondary_email = "notarightformat.com"
assert !user.save
user.secondary_email = "not@arightformatcom"
assert !user.save
end
should 'return an error if secondary email is governmental and primary is not' do
user = fast_create(User)
user.email = "test@email.com"
user.secondary_email = "test@gov.br"
assert !user.save
assert user.errors.full_messages.include?("The governamental email must be the primary one.")
end
should 'have institution if email is governmental' do
user = fast_create(User)
user.email = "test@gov.br"
user.institutions = []
assert !user.save
institution = build_institution "Test simple institution"
institution.save
user.institutions << institution
assert user.save
end
private
def create_default_user
user = fast_create(User)
user.login = "a-login"
user.email = "primary@email.com"
user.secondary_email = "secondary@email.com"
user.save
return user
end
def build_institution name, type="PublicInstitution", cnpj=nil
institution = Institution::new
institution.name = name
institution.type = type
institution.cnpj = cnpj
institution.community = Community.create(:name => "Simple Public Institution")
institution.community.country = "BR"
institution.community.state = "DF"
institution.community.city = "Gama"
if type == "PublicInstitution"
institution.juridical_nature = JuridicalNature.first
end
institution
end
end