From 15d2984bdb486659418ebad237007e4201bba72e Mon Sep 17 00:00:00 2001 From: Arthur Del Esposte Date: Thu, 3 Sep 2015 17:18:52 -0300 Subject: [PATCH] Remove user validations for governemental users --- lib/ext/person.rb | 1 + lib/ext/user.rb | 32 +------------------------------- test/unit/user_test.rb | 39 --------------------------------------- 3 files changed, 2 insertions(+), 70 deletions(-) diff --git a/lib/ext/person.rb b/lib/ext/person.rb index 32a42b0..0260a99 100644 --- a/lib/ext/person.rb +++ b/lib/ext/person.rb @@ -13,6 +13,7 @@ class Person def institution? false end + def secondary_email self.user.secondary_email unless self.user.nil? end diff --git a/lib/ext/user.rb b/lib/ext/user.rb index 7663045..ec5f7ce 100644 --- a/lib/ext/user.rb +++ b/lib/ext/user.rb @@ -7,7 +7,7 @@ class User has_and_belongs_to_many :institutions validate :email_different_secondary?, :email_has_already_been_used?, - :secondary_email_format, :email_suffix_is_gov? + :secondary_email_format scope :primary_or_secondary_email_already_used?, lambda { |email| where("email=? OR secondary_email=?", email, email) @@ -52,39 +52,9 @@ class User end end - def email_suffix_is_gov? - check_gov_suffix_in_secondary_email - check_gov_email_have_institution - end - private def valid_format?(value, string_format) !value.nil? && value.length > 0 && !string_format.match(value).nil? end - - def check_gov_suffix_in_secondary_email - unless primary_email_has_gov_suffix? - self.errors.add( - :base, - _("The governamental email must be the primary one.") - ) if secondary_email_has_gov_suffix? - end - end - - def check_gov_email_have_institution - self.errors.add( - :base, - _("Institution is obligatory if user has a government email.") - ) if primary_email_has_gov_suffix? && self.institutions.blank? - end - - def primary_email_has_gov_suffix? - valid_format?(self.email, GOV_SUFFIX) - end - - def secondary_email_has_gov_suffix? - valid_format?(self.secondary_email, GOV_SUFFIX) - end - end diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index 82c1900..c2b15c6 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -84,45 +84,6 @@ class UserTest < ActiveSupport::TestCase assert user2.save end - should 'return an error if secondary email is governmental and primary is not' do - invalid_msg = "The governamental email must be the primary one." - user = fast_create(User) - - user.email = "test@email.com" - user.secondary_email = "test@gov.br" - - assert !user.save - assert user.errors.full_messages.include?(invalid_msg) - end - - # should 'have institution if email is governmental' do - # user = fast_create(User) - # - # user.email = "testtest@gov.br" - # - # user.institutions = [] - # assert !user.save, "this should not save" - # - # gov_power = GovernmentalPower.create(:name=>"Some Gov Power") - # gov_sphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") - # juridical_nature = JuridicalNature.create(:name => "Autarquia") - # institution = create_public_institution( - # "Ministerio Publico da Uniao", - # "MPU", - # "BR", - # "DF", - # "Gama", - # juridical_nature, - # gov_power, - # gov_sphere, - # "44.555.666/7777-88" - # ) - # institution.save! - # - # user.institutions << institution - # assert user.save, "this should save" - # end - private def create_default_user -- libgit2 0.21.2