Commit 6223c23b09bfd6239ef567a905bc16f74cd2cf4e

Authored by Luciano Prestes
Committed by Thiago Ribeiro
1 parent cb896ae4
Exists in master and in 79 other branches add_sisp_to_chef, add_super_archives_plugin, api_for_colab, automates_core_packing, backup_not_prod, changes_in_buttons_on_content_panel, colab_automated_login, colab_spb_plugin_recipe, colab_widgets_settings, design_validation, dev_env_minimal, disable_email_dev, fix_breadcrumbs_position, fix_categories_software_link, fix_edit_institution, fix_edit_software_with_another_license, fix_get_license_info, fix_gitlab_assets_permission, fix_list_style_inside_article, fix_list_style_on_folder_elements, fix_members_pagination, fix_merge_request_url, fix_models_translations, fix_no_license, fix_software_api, fix_software_block_migration, fix_software_communities_translations, fix_software_communities_unit_test, fix_style_create_institution_admin_panel, fix_superarchives_imports, fix_sym_links_noosfero, focus_search_field_theme, gov-user-refactoring, gov-user-refactoring-rails4, header_fix, institution_modal_on_rating, kalibro-conf-refactoring, kalibro-processor-package, lxc_settings, margin_fix, mezuro_cookbook, prezento, refactor_download_block, refactor_software_communities, refactor_software_for_sisp, register_page, release-process, release-process-v2, remove-unused-images, remove_broken_theme, remove_secondary_email_from_user, remove_sisp_buttons, removing_super_archives_email, review_message, scope2method, signals_user_noosfero, sisp_catalog_header, sisp_colab_config, sisp_dev, sisp_dev_master, sisp_simple_version, software_as_organization, software_catalog_style_fix, software_communities_html_refactor, software_infos_api, spb_minimal_env, spb_to_rails4, spec_refactor, stable-4.1, stable-4.2, stable-4.x, temp_soft_comm_refactoring, theme_header, theme_javascript_refactory, thread_dropdown, thread_page, update_search_by_categories, update_software_api, update_softwares_boxes

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>
lib/institution.rb
@@ -23,8 +23,7 @@ class Institution &lt; ActiveRecord::Base @@ -23,8 +23,7 @@ class Institution &lt; 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 &lt; ActiveRecord::Base @@ -35,7 +34,7 @@ class Institution &lt; 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 &lt; ActiveRecord::Base @@ -57,7 +56,7 @@ class Institution &lt; 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 &lt; ActiveRecord::Base @@ -94,7 +93,8 @@ class Institution &lt; 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 &lt; ActiveRecord::Base @@ -105,15 +105,4 @@ class Institution &lt; 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 &lt; ActiveSupport::TestCase @@ -19,11 +19,10 @@ class PrivateInstitutionTest &lt; 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 &lt; ActiveSupport::TestCase @@ -32,9 +32,9 @@ class PublicInstitutionTest &lt; 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">