Commit 2adffb01a1e28d9fa0928516dc920067f79b30e1

Authored by Gabriela Navarro
Committed by Gust
1 parent 7c6a23c0

instituion_fields: New validations to institution.

Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
Signed-off-by: Parley Martins <parley@outlook.com>
Showing 2 changed files with 19 additions and 3 deletions   Show diff stats
lib/institution.rb
... ... @@ -15,11 +15,13 @@ class Institution &lt; ActiveRecord::Base
15 15 before_save :verify_institution_type
16 16  
17 17 belongs_to :community
18   -
  18 +
19 19 scope :search_institution, lambda{ |value|
20 20 where("name ilike ? OR acronym ilike ?", "%#{value}%", "%#{value}%" )
21 21 }
22 22  
  23 + validate :validate_country, :validate_state, :validate_city
  24 +
23 25 protected
24 26  
25 27 def verify_institution_type
... ... @@ -30,4 +32,16 @@ class Institution &lt; ActiveRecord::Base
30 32 false
31 33 end
32 34 end
  35 +
  36 + def validate_country
  37 + self.errors.add(:country, _("can't be blank")) if self.community.country.blank? && self.errors[:country].blank?
  38 + end
  39 +
  40 + def validate_state
  41 + self.errors.add(:state, _("can't be blank")) if self.community.state.blank? && self.errors[:state].blank?
  42 + end
  43 +
  44 + def validate_city
  45 + self.errors.add(:city, _("can't be blank")) if self.community.city.blank? && self.errors[:city].blank?
  46 + end
33 47 end
... ...
lib/public_institution.rb
1 1 class PublicInstitution < Institution
2   - validates :acronym, :governmental_power, :governmental_sphere, :presence=>true
  2 + validates :governmental_power, :governmental_sphere, :juridical_nature, :presence=>true
  3 + validates_uniqueness_of :acronym, :allow_blank => true, :allow_nil => true
3 4 validates_uniqueness_of :cnpj, :unit_code, :allow_nil => true, :allow_blank => true
4 5 validates_format_of :cnpj, :with => /^\d{2}\.\d{3}\.\d{3}\/\d{4}\-\d{2}$/, :allow_nil => true, :allow_blank => true
5   -end
6 6 \ No newline at end of file
  7 +
  8 +end
... ...