Commit 6223c23b09bfd6239ef567a905bc16f74cd2cf4e
Committed by
Thiago Ribeiro
1 parent
cb896ae4
Exists in
master
and in
3 other branches
Remove validates presence of cnpj and coroporate name
Signed-off-by: Luciano Prestes Cavalcanti <lucianopcbr@gmail.com> Signed-off-by: Simiao Carvalho <simiaosimis@gmail.com>
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,8 +23,7 @@ class Institution < ActiveRecord::Base | ||
23 | :corporate_name | 23 | :corporate_name |
24 | 24 | ||
25 | validates :name, :presence=>true, :uniqueness=>true | 25 | validates :name, :presence=>true, :uniqueness=>true |
26 | - | ||
27 | - validates :corporate_name, :presence => true | 26 | + validates :cnpj, :uniqueness=>true |
28 | 27 | ||
29 | before_save :verify_institution_type | 28 | before_save :verify_institution_type |
30 | 29 | ||
@@ -35,7 +34,7 @@ class Institution < ActiveRecord::Base | @@ -35,7 +34,7 @@ class Institution < ActiveRecord::Base | ||
35 | } | 34 | } |
36 | 35 | ||
37 | validate :validate_country, :validate_state, :validate_city, | 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 | protected | 40 | protected |
@@ -57,7 +56,7 @@ class Institution < ActiveRecord::Base | @@ -57,7 +56,7 @@ class Institution < ActiveRecord::Base | ||
57 | 56 | ||
58 | def validate_country | 57 | def validate_country |
59 | unless self.community.blank? | 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 | self.errors.add(:country, _("can't be blank")) | 60 | self.errors.add(:country, _("can't be blank")) |
62 | return false | 61 | return false |
63 | end | 62 | end |
@@ -94,7 +93,8 @@ class Institution < ActiveRecord::Base | @@ -94,7 +93,8 @@ class Institution < ActiveRecord::Base | ||
94 | end | 93 | end |
95 | 94 | ||
96 | def validate_format_cnpj | 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 | format = /^\d{2}\.\d{3}\.\d{3}\/\d{4}\-\d{2}$/ | 99 | format = /^\d{2}\.\d{3}\.\d{3}\/\d{4}\-\d{2}$/ |
100 | 100 | ||
@@ -105,15 +105,4 @@ class Institution < ActiveRecord::Base | @@ -105,15 +105,4 @@ class Institution < ActiveRecord::Base | ||
105 | return false | 105 | return false |
106 | end | 106 | end |
107 | end | 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 | end | 108 | end |
test/unit/private_institution_test.rb
@@ -19,11 +19,10 @@ class PrivateInstitutionTest < ActiveSupport::TestCase | @@ -19,11 +19,10 @@ class PrivateInstitutionTest < ActiveSupport::TestCase | ||
19 | Institution.destroy_all | 19 | Institution.destroy_all |
20 | end | 20 | end |
21 | 21 | ||
22 | - should "not save without a cnpj" do | 22 | + should "save without a cnpj" do |
23 | @institution.cnpj = nil | 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 | end | 26 | end |
28 | 27 | ||
29 | should "not save with a repeated cnpj" do | 28 | should "not save with a repeated cnpj" do |
test/unit/public_institution_test.rb
@@ -32,9 +32,9 @@ class PublicInstitutionTest < ActiveSupport::TestCase | @@ -32,9 +32,9 @@ class PublicInstitutionTest < ActiveSupport::TestCase | ||
32 | @institution = nil | 32 | @institution = nil |
33 | end | 33 | end |
34 | 34 | ||
35 | - should "not save without a cnpj" do | 35 | + should "save without a cnpj" do |
36 | @institution.cnpj = nil | 36 | @institution.cnpj = nil |
37 | - assert !@institution.save | 37 | + assert @institution.save |
38 | end | 38 | end |
39 | 39 | ||
40 | should "save institution without an acronym" do | 40 | should "save institution without an acronym" do |
views/gov_user_plugin/_institution.html.erb
@@ -43,10 +43,10 @@ | @@ -43,10 +43,10 @@ | ||
43 | <%= required f.text_field(:name, :class => flash[:error_community_name], :value => params[:community][:name]) %> | 43 | <%= required f.text_field(:name, :class => flash[:error_community_name], :value => params[:community][:name]) %> |
44 | <%= content_tag :span, _("Institution name already exists"), :id=>"already_exists_text", :class=>"errorExplanation hide-field" %> | 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 | <div class="formfield type-text"> | 47 | <div class="formfield type-text"> |
48 | <%= inst.label "corporate_name", _("Corporate Name"), :class=>"formlabel" %> | 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 | </div> | 50 | </div> |
51 | </span> | 51 | </span> |
52 | 52 | ||
@@ -62,12 +62,10 @@ | @@ -62,12 +62,10 @@ | ||
62 | <%= required f.text_field(:city, :class => flash[:error_community_city], :value => params[:community][:city]) %> | 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 | <span class='optional-field'> | 70 | <span class='optional-field'> |
73 | <div class="formfield type-text"> | 71 | <div class="formfield type-text"> |