Commit 784089f42bce1ab00cd3a6e83275d14100f409fe
Committed by
Fabio Teixeira
1 parent
b2b92046
Exists in
master
and in
3 other branches
Fix validations and identation problems
Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
Showing
4 changed files
with
32 additions
and
35 deletions
Show diff stats
controllers/gov_user_plugin_controller.rb
| @@ -140,11 +140,10 @@ class GovUserPluginController < ApplicationController | @@ -140,11 +140,10 @@ class GovUserPluginController < ApplicationController | ||
| 140 | end | 140 | end |
| 141 | 141 | ||
| 142 | def set_institution_type | 142 | def set_institution_type |
| 143 | - institution_params = params[:institutions].except( | ||
| 144 | - :governmental_power, | ||
| 145 | - :governmental_sphere, | ||
| 146 | - :juridical_nature | ||
| 147 | - ) | 143 | + institution_params = params[:institutions].except(:governmental_power, |
| 144 | + :governmental_sphere, | ||
| 145 | + :juridical_nature | ||
| 146 | + ) | ||
| 148 | if params[:institutions][:type] == "PublicInstitution" | 147 | if params[:institutions][:type] == "PublicInstitution" |
| 149 | PublicInstitution::new institution_params | 148 | PublicInstitution::new institution_params |
| 150 | else | 149 | else |
| @@ -165,8 +164,8 @@ class GovUserPluginController < ApplicationController | @@ -165,8 +164,8 @@ class GovUserPluginController < ApplicationController | ||
| 165 | institution.governmental_sphere = gov_sphere | 164 | institution.governmental_sphere = gov_sphere |
| 166 | rescue | 165 | rescue |
| 167 | institution.errors.add( | 166 | institution.errors.add( |
| 168 | - :governmental_fields, | ||
| 169 | - _("Could not find Governmental Power or Governmental Sphere") | 167 | + :governmental_fields, |
| 168 | + _("Could not find Governmental Power or Governmental Sphere") | ||
| 170 | ) | 169 | ) |
| 171 | end | 170 | end |
| 172 | end | 171 | end |
lib/institution.rb
| @@ -50,47 +50,45 @@ class Institution < ActiveRecord::Base | @@ -50,47 +50,45 @@ class Institution < ActiveRecord::Base | ||
| 50 | 50 | ||
| 51 | return false | 51 | return false |
| 52 | end | 52 | end |
| 53 | + | ||
| 53 | return true | 54 | return true |
| 54 | end | 55 | end |
| 55 | 56 | ||
| 56 | def validate_country | 57 | def validate_country |
| 57 | - if(self.community.blank? || | ||
| 58 | - self.community.country.blank? && | ||
| 59 | - self.errors[:country].blank?) | ||
| 60 | - | ||
| 61 | - self.errors.add(:country, _("can't be blank")) | ||
| 62 | - return false | 58 | + unless self.community.blank? |
| 59 | + if self.community.country.blank? && self.errors[:country].blank? | ||
| 60 | + self.errors.add(:country, _("can't be blank")) | ||
| 61 | + return false | ||
| 62 | + end | ||
| 63 | end | 63 | end |
| 64 | + | ||
| 64 | return true | 65 | return true |
| 65 | end | 66 | end |
| 66 | 67 | ||
| 67 | def validate_state | 68 | def validate_state |
| 68 | - if(self.community.blank? || | ||
| 69 | - self.errors[:state].blank? && | ||
| 70 | - (self.community.state.blank? || self.community.state == "-1")) | 69 | + unless self.community.blank? |
| 70 | + if self.community.country == "BR" && | ||
| 71 | + (self.community.state.blank? || self.community.state == "-1") && | ||
| 72 | + self.errors[:state].blank? | ||
| 71 | 73 | ||
| 72 | - if self.community.country == "BR" | ||
| 73 | self.errors.add(:state, _("can't be blank")) | 74 | self.errors.add(:state, _("can't be blank")) |
| 74 | return false | 75 | return false |
| 75 | - else | ||
| 76 | - return true | ||
| 77 | end | 76 | end |
| 78 | end | 77 | end |
| 78 | + | ||
| 79 | return true | 79 | return true |
| 80 | end | 80 | end |
| 81 | 81 | ||
| 82 | def validate_city | 82 | def validate_city |
| 83 | - if(self.community.blank? || | ||
| 84 | - self.errors[:city].blank? && | ||
| 85 | - self.community.city.blank?) | 83 | + unless self.community.blank? |
| 84 | + if self.community.country == "BR" && self.community.city.blank? && | ||
| 85 | + self.errors[:city].blank? | ||
| 86 | 86 | ||
| 87 | - if self.community.country == "BR" | ||
| 88 | self.errors.add(:city, _("can't be blank")) | 87 | self.errors.add(:city, _("can't be blank")) |
| 89 | return false | 88 | return false |
| 90 | - else | ||
| 91 | - return true | ||
| 92 | end | 89 | end |
| 93 | end | 90 | end |
| 91 | + | ||
| 94 | return true | 92 | return true |
| 95 | end | 93 | end |
| 96 | 94 | ||
| @@ -109,14 +107,12 @@ class Institution < ActiveRecord::Base | @@ -109,14 +107,12 @@ class Institution < ActiveRecord::Base | ||
| 109 | 107 | ||
| 110 | def validate_cnpj | 108 | def validate_cnpj |
| 111 | if !self.community.blank? && self.community.country == "BR" | 109 | if !self.community.blank? && self.community.country == "BR" |
| 112 | - if self.errors[:cnpj].blank? && self.cnpj.blank? | 110 | + if self.cnpj.blank? && self.errors[:cnpj].blank? |
| 113 | self.errors.add(:cnpj, _("can't be blank")) | 111 | self.errors.add(:cnpj, _("can't be blank")) |
| 114 | return false | 112 | return false |
| 115 | - else | ||
| 116 | - return true | ||
| 117 | end | 113 | end |
| 118 | - else | ||
| 119 | - return true | ||
| 120 | end | 114 | end |
| 115 | + | ||
| 116 | + return true | ||
| 121 | end | 117 | end |
| 122 | end | 118 | end |
test/functional/gov_user_plugin_controller_test.rb
| @@ -44,6 +44,7 @@ class GovUserPluginControllerTest < ActionController::TestCase | @@ -44,6 +44,7 @@ class GovUserPluginControllerTest < ActionController::TestCase | ||
| 44 | @gov_sphere, | 44 | @gov_sphere, |
| 45 | "12.345.678/9012-90" | 45 | "12.345.678/9012-90" |
| 46 | ) | 46 | ) |
| 47 | + | ||
| 47 | end | 48 | end |
| 48 | 49 | ||
| 49 | should "Search for institution with acronym" do | 50 | should "Search for institution with acronym" do |
| @@ -228,6 +229,7 @@ class GovUserPluginControllerTest < ActionController::TestCase | @@ -228,6 +229,7 @@ class GovUserPluginControllerTest < ActionController::TestCase | ||
| 228 | xhr :post, :new_institution, fields | 229 | xhr :post, :new_institution, fields |
| 229 | 230 | ||
| 230 | json_response = ActiveSupport::JSON.decode(@response.body) | 231 | json_response = ActiveSupport::JSON.decode(@response.body) |
| 232 | + | ||
| 231 | assert json_response["success"] | 233 | assert json_response["success"] |
| 232 | end | 234 | end |
| 233 | 235 |
views/gov_user_plugin/_institution.html.erb
| @@ -58,7 +58,7 @@ | @@ -58,7 +58,7 @@ | ||
| 58 | <span class='required-field'> | 58 | <span class='required-field'> |
| 59 | <div class="formfield"> | 59 | <div class="formfield"> |
| 60 | <label for="community_state" class="formlabel"><%= _("State") %></label> | 60 | <label for="community_state" class="formlabel"><%= _("State") %></label> |
| 61 | - <%= f.select(:state, @state_options, {}, {:class => flash[:error_community_state]}) %> | 61 | + <%= f.select(:state, @state_options, {:selected => params[:community][:state]}, {:class => flash[:error_community_state]}) %> |
| 62 | </div> | 62 | </div> |
| 63 | </span> | 63 | </span> |
| 64 | 64 | ||
| @@ -77,27 +77,27 @@ | @@ -77,27 +77,27 @@ | ||
| 77 | <%= hidden_field_tag "acronym_translate", _("Acronym") %> | 77 | <%= hidden_field_tag "acronym_translate", _("Acronym") %> |
| 78 | <%= hidden_field_tag "fantasy_name_translate", _("Fantasy name") %> | 78 | <%= hidden_field_tag "fantasy_name_translate", _("Fantasy name") %> |
| 79 | <%= inst.label("acronym" ,_("Acronym"), :class=>"formlabel") %> | 79 | <%= inst.label("acronym" ,_("Acronym"), :class=>"formlabel") %> |
| 80 | - <%= inst.text_field(:acronym) %> | 80 | + <%= inst.text_field(:acronym, :value => params[:institutions][:acronym]) %> |
| 81 | </div> | 81 | </div> |
| 82 | </span> | 82 | </span> |
| 83 | 83 | ||
| 84 | <span class='required-field public-institutions-fields'> | 84 | <span class='required-field public-institutions-fields'> |
| 85 | <div class="formfield type-text"> | 85 | <div class="formfield type-text"> |
| 86 | <%= inst.label("governmental_sphere_id" ,_("Governmental Sphere:"), :class=>"formlabel") %> | 86 | <%= inst.label("governmental_sphere_id" ,_("Governmental Sphere:"), :class=>"formlabel") %> |
| 87 | - <%= inst.select(:governmental_sphere, @governmental_sphere, {:selected=>0}, :class => flash[:error_institution_governmental_sphere])%> | 87 | + <%= inst.select(:governmental_sphere, @governmental_sphere, :selected=>params[:institutions][:governmental_sphere], :class => flash[:error_institution_governmental_sphere])%> |
| 88 | </div> | 88 | </div> |
| 89 | </span> | 89 | </span> |
| 90 | 90 | ||
| 91 | <span class='required-field public-institutions-fields'> | 91 | <span class='required-field public-institutions-fields'> |
| 92 | <div class="formfield type-text"> | 92 | <div class="formfield type-text"> |
| 93 | <%= inst.label("governmental_power_id" ,_("Governmental Power:"), :class=>"formlabel") %> | 93 | <%= inst.label("governmental_power_id" ,_("Governmental Power:"), :class=>"formlabel") %> |
| 94 | - <%= inst.select(:governmental_power, @governmental_power, {:selected=>0}, {:class => flash[:error_institution_governmental_power]})%> | 94 | + <%= inst.select(:governmental_power, @governmental_power, :selected=>params[:institutions][:governmental_sphere], :class => flash[:error_institution_governmental_power])%> |
| 95 | </div> | 95 | </div> |
| 96 | </span> | 96 | </span> |
| 97 | <span class='required-field public-institutions-fields'> | 97 | <span class='required-field public-institutions-fields'> |
| 98 | <div class="formfield type-text"> | 98 | <div class="formfield type-text"> |
| 99 | <%= inst.label("juridical_nature_id" ,_("Juridical Nature:"), :class=>"formlabel") %> | 99 | <%= inst.label("juridical_nature_id" ,_("Juridical Nature:"), :class=>"formlabel") %> |
| 100 | - <%= inst.select(:juridical_nature, @juridical_nature, {:selected=>0}, {:class => flash[:error_institution_juridical_nature]})%> | 100 | + <%= inst.select(:juridical_nature, @juridical_nature, :selected=>params[:institutions][:juridical_nature], :class => flash[:error_institution_juridical_nature])%> |
| 101 | </div> | 101 | </div> |
| 102 | </span> | 102 | </span> |
| 103 | 103 |