Commit 15d2984bdb486659418ebad237007e4201bba72e
1 parent
2847cdb2
Exists in
master
and in
3 other branches
Remove user validations for governemental users
Showing
3 changed files
with
2 additions
and
70 deletions
Show diff stats
lib/ext/person.rb
lib/ext/user.rb
| ... | ... | @@ -7,7 +7,7 @@ class User |
| 7 | 7 | has_and_belongs_to_many :institutions |
| 8 | 8 | |
| 9 | 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 | 12 | scope :primary_or_secondary_email_already_used?, lambda { |email| |
| 13 | 13 | where("email=? OR secondary_email=?", email, email) |
| ... | ... | @@ -52,39 +52,9 @@ class User |
| 52 | 52 | end |
| 53 | 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 | 55 | private |
| 61 | 56 | |
| 62 | 57 | def valid_format?(value, string_format) |
| 63 | 58 | !value.nil? && value.length > 0 && !string_format.match(value).nil? |
| 64 | 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 | 60 | end | ... | ... |
test/unit/user_test.rb
| ... | ... | @@ -84,45 +84,6 @@ class UserTest < ActiveSupport::TestCase |
| 84 | 84 | assert user2.save |
| 85 | 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 | 87 | private |
| 127 | 88 | |
| 128 | 89 | def create_default_user | ... | ... |