Commit 701c0b287a6bd377332e3b45e32f2f639c7bea60
Exists in
master
and in
3 other branches
Merge branch 'fix_institution_registration' into 'master'
Fix institution registration See merge request !3
Showing
4 changed files
with
15 additions
and
29 deletions
Show diff stats
lib/institution.rb
... | ... | @@ -23,8 +23,7 @@ class Institution < ActiveRecord::Base |
23 | 23 | :corporate_name |
24 | 24 | |
25 | 25 | validates :name, :presence=>true, :uniqueness=>true |
26 | - | |
27 | - validates :corporate_name, :presence => true | |
26 | + validates :cnpj, :uniqueness=>true | |
28 | 27 | |
29 | 28 | before_save :verify_institution_type |
30 | 29 | |
... | ... | @@ -35,7 +34,7 @@ class Institution < ActiveRecord::Base |
35 | 34 | } |
36 | 35 | |
37 | 36 | validate :validate_country, :validate_state, :validate_city, |
38 | - :verify_institution_type, :validate_cnpj, :validate_format_cnpj | |
37 | + :verify_institution_type, :validate_format_cnpj | |
39 | 38 | |
40 | 39 | |
41 | 40 | protected |
... | ... | @@ -57,7 +56,7 @@ class Institution < ActiveRecord::Base |
57 | 56 | |
58 | 57 | def validate_country |
59 | 58 | unless self.community.blank? |
60 | - if self.community.country.blank? && self.errors[:country].blank? | |
59 | + if self.community.country.blank? && self.errors[:country].blank? | |
61 | 60 | self.errors.add(:country, _("can't be blank")) |
62 | 61 | return false |
63 | 62 | end |
... | ... | @@ -94,7 +93,8 @@ class Institution < ActiveRecord::Base |
94 | 93 | end |
95 | 94 | |
96 | 95 | def validate_format_cnpj |
97 | - return true if !self.community.blank? && self.community.country != "BR" | |
96 | + return true if self.community.blank? && self.community.country != "BR" | |
97 | + return true if self.cnpj.blank? | |
98 | 98 | |
99 | 99 | format = /^\d{2}\.\d{3}\.\d{3}\/\d{4}\-\d{2}$/ |
100 | 100 | |
... | ... | @@ -105,15 +105,4 @@ class Institution < ActiveRecord::Base |
105 | 105 | return false |
106 | 106 | end |
107 | 107 | end |
108 | - | |
109 | - def validate_cnpj | |
110 | - if !self.community.blank? && self.community.country == "BR" | |
111 | - if self.cnpj.blank? && self.errors[:cnpj].blank? | |
112 | - self.errors.add(:cnpj, _("can't be blank")) | |
113 | - return false | |
114 | - end | |
115 | - end | |
116 | - | |
117 | - return true | |
118 | - end | |
119 | 108 | end | ... | ... |
test/unit/private_institution_test.rb
... | ... | @@ -19,11 +19,10 @@ class PrivateInstitutionTest < ActiveSupport::TestCase |
19 | 19 | Institution.destroy_all |
20 | 20 | end |
21 | 21 | |
22 | - should "not save without a cnpj" do | |
22 | + should "save without a cnpj" do | |
23 | 23 | @institution.cnpj = nil |
24 | 24 | |
25 | - assert !@institution.save | |
26 | - assert @institution.errors.full_messages.include? "Cnpj can't be blank" | |
25 | + assert @institution.save | |
27 | 26 | end |
28 | 27 | |
29 | 28 | should "not save with a repeated cnpj" do | ... | ... |
test/unit/public_institution_test.rb
... | ... | @@ -32,9 +32,9 @@ class PublicInstitutionTest < ActiveSupport::TestCase |
32 | 32 | @institution = nil |
33 | 33 | end |
34 | 34 | |
35 | - should "not save without a cnpj" do | |
35 | + should "save without a cnpj" do | |
36 | 36 | @institution.cnpj = nil |
37 | - assert !@institution.save | |
37 | + assert @institution.save | |
38 | 38 | end |
39 | 39 | |
40 | 40 | should "save institution without an acronym" do | ... | ... |
views/gov_user_plugin/_institution.html.erb
... | ... | @@ -43,10 +43,10 @@ |
43 | 43 | <%= required f.text_field(:name, :class => flash[:error_community_name], :value => params[:community][:name]) %> |
44 | 44 | <%= content_tag :span, _("Institution name already exists"), :id=>"already_exists_text", :class=>"errorExplanation hide-field" %> |
45 | 45 | |
46 | - <span class='required-field'> | |
46 | + <span class='optional-field'> | |
47 | 47 | <div class="formfield type-text"> |
48 | 48 | <%= inst.label "corporate_name", _("Corporate Name"), :class=>"formlabel" %> |
49 | - <%= required inst.text_field(:corporate_name, :value => params[:institutions][:corporate_name], :size => 55, :class => flash[:error_institution_corporate_name]) %> | |
49 | + <%= inst.text_field(:corporate_name, :value => params[:institutions][:corporate_name], :size => 55) %> | |
50 | 50 | </div> |
51 | 51 | </span> |
52 | 52 | |
... | ... | @@ -62,12 +62,10 @@ |
62 | 62 | <%= required f.text_field(:city, :class => flash[:error_community_city], :value => params[:community][:city]) %> |
63 | 63 | |
64 | 64 | |
65 | - <span class='required-field'> | |
66 | - <div class="formfield type-text"> | |
67 | - <%= inst.label("cnpj" ,_("CNPJ"), :class=>"formlabel") %> | |
68 | - <%= required inst.text_field(:cnpj, :placeholder=>"99.999.999/9999-99", :class=>"intitution_cnpj_field #{flash[:error_institution_cnpj]}", :value => params[:institutions][:cnpj]) %> | |
69 | - </div> | |
70 | - </span> | |
65 | + <div class="formfield type-text"> | |
66 | + <%= inst.label("cnpj" ,_("CNPJ"), :class=>"formlabel") %> | |
67 | + <%= required inst.text_field(:cnpj, :placeholder=>"99.999.999/9999-99", :class=>"intitution_cnpj_field", :value => params[:institutions][:cnpj]) %> | |
68 | + </div> | |
71 | 69 | |
72 | 70 | <span class='optional-field'> |
73 | 71 | <div class="formfield type-text"> | ... | ... |