Commit 05dce99b95aea9cc36deb6d0f1fe3cb498be9abb
Committed by
Arthur Esposte
1 parent
a04fdedc
Exists in
master
and in
5 other branches
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 < ActiveRecord::Base | @@ -15,11 +15,13 @@ class Institution < ActiveRecord::Base | ||
| 15 | before_save :verify_institution_type | 15 | before_save :verify_institution_type |
| 16 | 16 | ||
| 17 | belongs_to :community | 17 | belongs_to :community |
| 18 | - | 18 | + |
| 19 | scope :search_institution, lambda{ |value| | 19 | scope :search_institution, lambda{ |value| |
| 20 | where("name ilike ? OR acronym ilike ?", "%#{value}%", "%#{value}%" ) | 20 | where("name ilike ? OR acronym ilike ?", "%#{value}%", "%#{value}%" ) |
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | + validate :validate_country, :validate_state, :validate_city | ||
| 24 | + | ||
| 23 | protected | 25 | protected |
| 24 | 26 | ||
| 25 | def verify_institution_type | 27 | def verify_institution_type |
| @@ -30,4 +32,16 @@ class Institution < ActiveRecord::Base | @@ -30,4 +32,16 @@ class Institution < ActiveRecord::Base | ||
| 30 | false | 32 | false |
| 31 | end | 33 | end |
| 32 | end | 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 | end | 47 | end |
lib/public_institution.rb
| 1 | class PublicInstitution < Institution | 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 | validates_uniqueness_of :cnpj, :unit_code, :allow_nil => true, :allow_blank => true | 4 | validates_uniqueness_of :cnpj, :unit_code, :allow_nil => true, :allow_blank => true |
| 4 | validates_format_of :cnpj, :with => /^\d{2}\.\d{3}\.\d{3}\/\d{4}\-\d{2}$/, :allow_nil => true, :allow_blank => true | 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 | \ No newline at end of file | 6 | \ No newline at end of file |
| 7 | + | ||
| 8 | +end |