Commit 784089f42bce1ab00cd3a6e83275d14100f409fe

Authored by Gabriela Navarro
Committed by Fabio Teixeira
1 parent b2b92046

Fix validations and identation problems

Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
controllers/gov_user_plugin_controller.rb
... ... @@ -140,11 +140,10 @@ class GovUserPluginController &lt; ApplicationController
140 140 end
141 141  
142 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 147 if params[:institutions][:type] == "PublicInstitution"
149 148 PublicInstitution::new institution_params
150 149 else
... ... @@ -165,8 +164,8 @@ class GovUserPluginController &lt; ApplicationController
165 164 institution.governmental_sphere = gov_sphere
166 165 rescue
167 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 170 end
172 171 end
... ...
lib/institution.rb
... ... @@ -50,47 +50,45 @@ class Institution &lt; ActiveRecord::Base
50 50  
51 51 return false
52 52 end
  53 +
53 54 return true
54 55 end
55 56  
56 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 63 end
  64 +
64 65 return true
65 66 end
66 67  
67 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 74 self.errors.add(:state, _("can't be blank"))
74 75 return false
75   - else
76   - return true
77 76 end
78 77 end
  78 +
79 79 return true
80 80 end
81 81  
82 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 87 self.errors.add(:city, _("can't be blank"))
89 88 return false
90   - else
91   - return true
92 89 end
93 90 end
  91 +
94 92 return true
95 93 end
96 94  
... ... @@ -109,14 +107,12 @@ class Institution &lt; ActiveRecord::Base
109 107  
110 108 def validate_cnpj
111 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 111 self.errors.add(:cnpj, _("can't be blank"))
114 112 return false
115   - else
116   - return true
117 113 end
118   - else
119   - return true
120 114 end
  115 +
  116 + return true
121 117 end
122 118 end
... ...
test/functional/gov_user_plugin_controller_test.rb
... ... @@ -44,6 +44,7 @@ class GovUserPluginControllerTest &lt; ActionController::TestCase
44 44 @gov_sphere,
45 45 "12.345.678/9012-90"
46 46 )
  47 +
47 48 end
48 49  
49 50 should "Search for institution with acronym" do
... ... @@ -228,6 +229,7 @@ class GovUserPluginControllerTest &lt; ActionController::TestCase
228 229 xhr :post, :new_institution, fields
229 230  
230 231 json_response = ActiveSupport::JSON.decode(@response.body)
  232 +
231 233 assert json_response["success"]
232 234 end
233 235  
... ...
views/gov_user_plugin/_institution.html.erb
... ... @@ -58,7 +58,7 @@
58 58 <span class='required-field'>
59 59 <div class="formfield">
60 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 62 </div>
63 63 </span>
64 64  
... ... @@ -77,27 +77,27 @@
77 77 <%= hidden_field_tag "acronym_translate", _("Acronym") %>
78 78 <%= hidden_field_tag "fantasy_name_translate", _("Fantasy name") %>
79 79 <%= inst.label("acronym" ,_("Acronym"), :class=>"formlabel") %>
80   - <%= inst.text_field(:acronym) %>
  80 + <%= inst.text_field(:acronym, :value => params[:institutions][:acronym]) %>
81 81 </div>
82 82 </span>
83 83  
84 84 <span class='required-field public-institutions-fields'>
85 85 <div class="formfield type-text">
86 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 88 </div>
89 89 </span>
90 90  
91 91 <span class='required-field public-institutions-fields'>
92 92 <div class="formfield type-text">
93 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 95 </div>
96 96 </span>
97 97 <span class='required-field public-institutions-fields'>
98 98 <div class="formfield type-text">
99 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 101 </div>
102 102 </span>
103 103  
... ...