diff --git a/lib/institution.rb b/lib/institution.rb index 9477717..b63c5d7 100644 --- a/lib/institution.rb +++ b/lib/institution.rb @@ -23,8 +23,7 @@ class Institution < ActiveRecord::Base :corporate_name validates :name, :presence=>true, :uniqueness=>true - - validates :corporate_name, :presence => true + validates :cnpj, :uniqueness=>true before_save :verify_institution_type @@ -35,7 +34,7 @@ class Institution < ActiveRecord::Base } validate :validate_country, :validate_state, :validate_city, - :verify_institution_type, :validate_cnpj, :validate_format_cnpj + :verify_institution_type, :validate_format_cnpj protected @@ -57,7 +56,7 @@ class Institution < ActiveRecord::Base def validate_country unless self.community.blank? - if self.community.country.blank? && self.errors[:country].blank? + if self.community.country.blank? && self.errors[:country].blank? self.errors.add(:country, _("can't be blank")) return false end @@ -94,7 +93,8 @@ class Institution < ActiveRecord::Base end def validate_format_cnpj - return true if !self.community.blank? && self.community.country != "BR" + return true if self.community.blank? && self.community.country != "BR" + return true if self.cnpj.blank? format = /^\d{2}\.\d{3}\.\d{3}\/\d{4}\-\d{2}$/ @@ -105,15 +105,4 @@ class Institution < ActiveRecord::Base return false end end - - def validate_cnpj - if !self.community.blank? && self.community.country == "BR" - if self.cnpj.blank? && self.errors[:cnpj].blank? - self.errors.add(:cnpj, _("can't be blank")) - return false - end - end - - return true - end end diff --git a/test/unit/private_institution_test.rb b/test/unit/private_institution_test.rb index e0fad37..c87f6d3 100644 --- a/test/unit/private_institution_test.rb +++ b/test/unit/private_institution_test.rb @@ -19,11 +19,10 @@ class PrivateInstitutionTest < ActiveSupport::TestCase Institution.destroy_all end - should "not save without a cnpj" do + should "save without a cnpj" do @institution.cnpj = nil - assert !@institution.save - assert @institution.errors.full_messages.include? "Cnpj can't be blank" + assert @institution.save end should "not save with a repeated cnpj" do diff --git a/test/unit/public_institution_test.rb b/test/unit/public_institution_test.rb index 1976d0f..9f37965 100644 --- a/test/unit/public_institution_test.rb +++ b/test/unit/public_institution_test.rb @@ -32,9 +32,9 @@ class PublicInstitutionTest < ActiveSupport::TestCase @institution = nil end - should "not save without a cnpj" do + should "save without a cnpj" do @institution.cnpj = nil - assert !@institution.save + assert @institution.save end should "save institution without an acronym" do diff --git a/views/gov_user_plugin/_institution.html.erb b/views/gov_user_plugin/_institution.html.erb index 122a3e9..e2aa5b0 100644 --- a/views/gov_user_plugin/_institution.html.erb +++ b/views/gov_user_plugin/_institution.html.erb @@ -43,10 +43,10 @@ <%= required f.text_field(:name, :class => flash[:error_community_name], :value => params[:community][:name]) %> <%= content_tag :span, _("Institution name already exists"), :id=>"already_exists_text", :class=>"errorExplanation hide-field" %> - +
<%= inst.label "corporate_name", _("Corporate Name"), :class=>"formlabel" %> - <%= required inst.text_field(:corporate_name, :value => params[:institutions][:corporate_name], :size => 55, :class => flash[:error_institution_corporate_name]) %> + <%= inst.text_field(:corporate_name, :value => params[:institutions][:corporate_name], :size => 55) %>
@@ -62,12 +62,10 @@ <%= required f.text_field(:city, :class => flash[:error_community_city], :value => params[:community][:city]) %> - -
- <%= inst.label("cnpj" ,_("CNPJ"), :class=>"formlabel") %> - <%= required inst.text_field(:cnpj, :placeholder=>"99.999.999/9999-99", :class=>"intitution_cnpj_field #{flash[:error_institution_cnpj]}", :value => params[:institutions][:cnpj]) %> -
-
+
+ <%= inst.label("cnpj" ,_("CNPJ"), :class=>"formlabel") %> + <%= required inst.text_field(:cnpj, :placeholder=>"99.999.999/9999-99", :class=>"intitution_cnpj_field", :value => params[:institutions][:cnpj]) %> +
-- libgit2 0.21.2