diff --git a/controllers/gov_user_plugin_controller.rb b/controllers/gov_user_plugin_controller.rb
index 311b43b..80a41db 100644
--- a/controllers/gov_user_plugin_controller.rb
+++ b/controllers/gov_user_plugin_controller.rb
@@ -140,11 +140,10 @@ class GovUserPluginController < ApplicationController
end
def set_institution_type
- institution_params = params[:institutions].except(
- :governmental_power,
- :governmental_sphere,
- :juridical_nature
- )
+ institution_params = params[:institutions].except(:governmental_power,
+ :governmental_sphere,
+ :juridical_nature
+ )
if params[:institutions][:type] == "PublicInstitution"
PublicInstitution::new institution_params
else
@@ -165,8 +164,8 @@ class GovUserPluginController < ApplicationController
institution.governmental_sphere = gov_sphere
rescue
institution.errors.add(
- :governmental_fields,
- _("Could not find Governmental Power or Governmental Sphere")
+ :governmental_fields,
+ _("Could not find Governmental Power or Governmental Sphere")
)
end
end
diff --git a/lib/institution.rb b/lib/institution.rb
index 919a0ad..399c5f0 100644
--- a/lib/institution.rb
+++ b/lib/institution.rb
@@ -50,47 +50,45 @@ class Institution < ActiveRecord::Base
return false
end
+
return true
end
def validate_country
- if(self.community.blank? ||
- self.community.country.blank? &&
- self.errors[:country].blank?)
-
- self.errors.add(:country, _("can't be blank"))
- return false
+ unless self.community.blank?
+ if self.community.country.blank? && self.errors[:country].blank?
+ self.errors.add(:country, _("can't be blank"))
+ return false
+ end
end
+
return true
end
def validate_state
- if(self.community.blank? ||
- self.errors[:state].blank? &&
- (self.community.state.blank? || self.community.state == "-1"))
+ unless self.community.blank?
+ if self.community.country == "BR" &&
+ (self.community.state.blank? || self.community.state == "-1") &&
+ self.errors[:state].blank?
- if self.community.country == "BR"
self.errors.add(:state, _("can't be blank"))
return false
- else
- return true
end
end
+
return true
end
def validate_city
- if(self.community.blank? ||
- self.errors[:city].blank? &&
- self.community.city.blank?)
+ unless self.community.blank?
+ if self.community.country == "BR" && self.community.city.blank? &&
+ self.errors[:city].blank?
- if self.community.country == "BR"
self.errors.add(:city, _("can't be blank"))
return false
- else
- return true
end
end
+
return true
end
@@ -109,14 +107,12 @@ class Institution < ActiveRecord::Base
def validate_cnpj
if !self.community.blank? && self.community.country == "BR"
- if self.errors[:cnpj].blank? && self.cnpj.blank?
+ if self.cnpj.blank? && self.errors[:cnpj].blank?
self.errors.add(:cnpj, _("can't be blank"))
return false
- else
- return true
end
- else
- return true
end
+
+ return true
end
end
diff --git a/test/functional/gov_user_plugin_controller_test.rb b/test/functional/gov_user_plugin_controller_test.rb
index 753379e..a74454d 100644
--- a/test/functional/gov_user_plugin_controller_test.rb
+++ b/test/functional/gov_user_plugin_controller_test.rb
@@ -44,6 +44,7 @@ class GovUserPluginControllerTest < ActionController::TestCase
@gov_sphere,
"12.345.678/9012-90"
)
+
end
should "Search for institution with acronym" do
@@ -228,6 +229,7 @@ class GovUserPluginControllerTest < ActionController::TestCase
xhr :post, :new_institution, fields
json_response = ActiveSupport::JSON.decode(@response.body)
+
assert json_response["success"]
end
diff --git a/views/gov_user_plugin/_institution.html.erb b/views/gov_user_plugin/_institution.html.erb
index 17fb47a..66b0d72 100644
--- a/views/gov_user_plugin/_institution.html.erb
+++ b/views/gov_user_plugin/_institution.html.erb
@@ -58,7 +58,7 @@
- <%= f.select(:state, @state_options, {}, {:class => flash[:error_community_state]}) %>
+ <%= f.select(:state, @state_options, {:selected => params[:community][:state]}, {:class => flash[:error_community_state]}) %>
@@ -77,27 +77,27 @@
<%= hidden_field_tag "acronym_translate", _("Acronym") %>
<%= hidden_field_tag "fantasy_name_translate", _("Fantasy name") %>
<%= inst.label("acronym" ,_("Acronym"), :class=>"formlabel") %>
- <%= inst.text_field(:acronym) %>
+ <%= inst.text_field(:acronym, :value => params[:institutions][:acronym]) %>
<%= inst.label("governmental_sphere_id" ,_("Governmental Sphere:"), :class=>"formlabel") %>
- <%= inst.select(:governmental_sphere, @governmental_sphere, {:selected=>0}, :class => flash[:error_institution_governmental_sphere])%>
+ <%= inst.select(:governmental_sphere, @governmental_sphere, :selected=>params[:institutions][:governmental_sphere], :class => flash[:error_institution_governmental_sphere])%>
<%= inst.label("governmental_power_id" ,_("Governmental Power:"), :class=>"formlabel") %>
- <%= inst.select(:governmental_power, @governmental_power, {:selected=>0}, {:class => flash[:error_institution_governmental_power]})%>
+ <%= inst.select(:governmental_power, @governmental_power, :selected=>params[:institutions][:governmental_sphere], :class => flash[:error_institution_governmental_power])%>
<%= inst.label("juridical_nature_id" ,_("Juridical Nature:"), :class=>"formlabel") %>
- <%= inst.select(:juridical_nature, @juridical_nature, {:selected=>0}, {:class => flash[:error_institution_juridical_nature]})%>
+ <%= inst.select(:juridical_nature, @juridical_nature, :selected=>params[:institutions][:juridical_nature], :class => flash[:error_institution_juridical_nature])%>
--
libgit2 0.21.2