Commit 15d2984bdb486659418ebad237007e4201bba72e

Authored by Arthur Esposte
1 parent 2847cdb2

Remove user validations for governemental users

lib/ext/person.rb
@@ -13,6 +13,7 @@ class Person @@ -13,6 +13,7 @@ class Person
13 def institution? 13 def institution?
14 false 14 false
15 end 15 end
  16 +
16 def secondary_email 17 def secondary_email
17 self.user.secondary_email unless self.user.nil? 18 self.user.secondary_email unless self.user.nil?
18 end 19 end
lib/ext/user.rb
@@ -7,7 +7,7 @@ class User @@ -7,7 +7,7 @@ class User
7 has_and_belongs_to_many :institutions 7 has_and_belongs_to_many :institutions
8 8
9 validate :email_different_secondary?, :email_has_already_been_used?, 9 validate :email_different_secondary?, :email_has_already_been_used?,
10 - :secondary_email_format, :email_suffix_is_gov? 10 + :secondary_email_format
11 11
12 scope :primary_or_secondary_email_already_used?, lambda { |email| 12 scope :primary_or_secondary_email_already_used?, lambda { |email|
13 where("email=? OR secondary_email=?", email, email) 13 where("email=? OR secondary_email=?", email, email)
@@ -52,39 +52,9 @@ class User @@ -52,39 +52,9 @@ class User
52 end 52 end
53 end 53 end
54 54
55 - def email_suffix_is_gov?  
56 - check_gov_suffix_in_secondary_email  
57 - check_gov_email_have_institution  
58 - end  
59 -  
60 private 55 private
61 56
62 def valid_format?(value, string_format) 57 def valid_format?(value, string_format)
63 !value.nil? && value.length > 0 && !string_format.match(value).nil? 58 !value.nil? && value.length > 0 && !string_format.match(value).nil?
64 end 59 end
65 -  
66 - def check_gov_suffix_in_secondary_email  
67 - unless primary_email_has_gov_suffix?  
68 - self.errors.add(  
69 - :base,  
70 - _("The governamental email must be the primary one.")  
71 - ) if secondary_email_has_gov_suffix?  
72 - end  
73 - end  
74 -  
75 - def check_gov_email_have_institution  
76 - self.errors.add(  
77 - :base,  
78 - _("Institution is obligatory if user has a government email.")  
79 - ) if primary_email_has_gov_suffix? && self.institutions.blank?  
80 - end  
81 -  
82 - def primary_email_has_gov_suffix?  
83 - valid_format?(self.email, GOV_SUFFIX)  
84 - end  
85 -  
86 - def secondary_email_has_gov_suffix?  
87 - valid_format?(self.secondary_email, GOV_SUFFIX)  
88 - end  
89 -  
90 end 60 end
test/unit/user_test.rb
@@ -84,45 +84,6 @@ class UserTest < ActiveSupport::TestCase @@ -84,45 +84,6 @@ class UserTest < ActiveSupport::TestCase
84 assert user2.save 84 assert user2.save
85 end 85 end
86 86
87 - should 'return an error if secondary email is governmental and primary is not' do  
88 - invalid_msg = "The governamental email must be the primary one."  
89 - user = fast_create(User)  
90 -  
91 - user.email = "test@email.com"  
92 - user.secondary_email = "test@gov.br"  
93 -  
94 - assert !user.save  
95 - assert user.errors.full_messages.include?(invalid_msg)  
96 - end  
97 -  
98 - # should 'have institution if email is governmental' do  
99 - # user = fast_create(User)  
100 - #  
101 - # user.email = "testtest@gov.br"  
102 - #  
103 - # user.institutions = []  
104 - # assert !user.save, "this should not save"  
105 - #  
106 - # gov_power = GovernmentalPower.create(:name=>"Some Gov Power")  
107 - # gov_sphere = GovernmentalSphere.create(:name=>"Some Gov Sphere")  
108 - # juridical_nature = JuridicalNature.create(:name => "Autarquia")  
109 - # institution = create_public_institution(  
110 - # "Ministerio Publico da Uniao",  
111 - # "MPU",  
112 - # "BR",  
113 - # "DF",  
114 - # "Gama",  
115 - # juridical_nature,  
116 - # gov_power,  
117 - # gov_sphere,  
118 - # "44.555.666/7777-88"  
119 - # )  
120 - # institution.save!  
121 - #  
122 - # user.institutions << institution  
123 - # assert user.save, "this should save"  
124 - # end  
125 -  
126 private 87 private
127 88
128 def create_default_user 89 def create_default_user