Commit 50723d962c8690ee9e96a08256ec96290dcc1a0c
Committed by
Gabriela Navarro
1 parent
59de02bd
Exists in
master
and in
5 other branches
Fix secondary email bug and fix unit tests
Signed-off-by: Parley Martins <parley@outlook.com> Signed-off-by: Rodrigo Medeiros <rodrigo.mss01@gmail.com>
Showing
2 changed files
with
18 additions
and
4 deletions
Show diff stats
lib/ext/user.rb
| ... | ... | @@ -18,8 +18,11 @@ class User |
| 18 | 18 | def email_has_already_been_used? |
| 19 | 19 | user_already_saved = User.find(:first, :conditions=>["email = ?", self.email]) |
| 20 | 20 | |
| 21 | - if user_already_saved.nil? | |
| 21 | + if user_already_saved.nil? | |
| 22 | 22 | primary_email_hasnt_been_used = User.primary_or_secondary_email_already_used?(self.email).empty? |
| 23 | + if !self.secondary_email.nil? and self.secondary_email.empty? | |
| 24 | + self.secondary_email = nil | |
| 25 | + end | |
| 23 | 26 | secondary_email_hasnt_been_used = User.primary_or_secondary_email_already_used?(self.secondary_email).empty? |
| 24 | 27 | |
| 25 | 28 | if !primary_email_hasnt_been_used or !secondary_email_hasnt_been_used | ... | ... |
test/unit/mpog_user_test.rb
| ... | ... | @@ -71,6 +71,17 @@ class MpogSoftwarePluginUserTest < ActiveSupport::TestCase |
| 71 | 71 | assert !user.save |
| 72 | 72 | end |
| 73 | 73 | |
| 74 | + should 'save more than one user without secondary email' do | |
| 75 | + user = fast_create(User) | |
| 76 | + user.email = "test@email.com" | |
| 77 | + user.secondary_email = "" | |
| 78 | + user.save | |
| 79 | + | |
| 80 | + user2 = fast_create(User) | |
| 81 | + user2.email = "test2@email.com" | |
| 82 | + user2.secondary_email = "" | |
| 83 | + assert user2.save | |
| 84 | + end | |
| 74 | 85 | should 'return an error if secondary email is governmental and primary is not' do |
| 75 | 86 | user = fast_create(User) |
| 76 | 87 | |
| ... | ... | @@ -87,13 +98,13 @@ class MpogSoftwarePluginUserTest < ActiveSupport::TestCase |
| 87 | 98 | user.email = "test@gov.br" |
| 88 | 99 | |
| 89 | 100 | user.institutions = [] |
| 90 | - assert !user.save | |
| 101 | + assert !user.save, "this should not save" | |
| 91 | 102 | |
| 92 | 103 | institution = build_institution "Test simple institution" |
| 93 | 104 | institution.save |
| 94 | 105 | |
| 95 | 106 | user.institutions << institution |
| 96 | - assert user.save | |
| 107 | + assert user.save, "this should save" | |
| 97 | 108 | end |
| 98 | 109 | |
| 99 | 110 | private |
| ... | ... | @@ -114,7 +125,7 @@ class MpogSoftwarePluginUserTest < ActiveSupport::TestCase |
| 114 | 125 | institution.type = type |
| 115 | 126 | institution.cnpj = cnpj |
| 116 | 127 | |
| 117 | - institution.community = Community.create(:name => "Simple Public Institution") | |
| 128 | + institution.community = Community.create(:name => name) | |
| 118 | 129 | institution.community.country = "BR" |
| 119 | 130 | institution.community.state = "DF" |
| 120 | 131 | institution.community.city = "Gama" | ... | ... |