aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/chouette/stop_area.rb
diff options
context:
space:
mode:
authorXinhui2017-12-27 14:19:16 +0100
committerXinhui2017-12-27 14:37:30 +0100
commit4bc32eb584ed669a8859b4897d020781d2d4ff43 (patch)
tree796245f694c0cd6c0187297f2a1818ab864b467b /app/models/chouette/stop_area.rb
parent1e9b030411b11c1027695196b878b69d8301ddc8 (diff)
downloadchouette-core-4bc32eb584ed669a8859b4897d020781d2d4ff43.tar.bz2
Add validation on stop_area parent_id area_type
Refs #5313
Diffstat (limited to 'app/models/chouette/stop_area.rb')
-rw-r--r--app/models/chouette/stop_area.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/app/models/chouette/stop_area.rb b/app/models/chouette/stop_area.rb
index 1dfdac724..08a5d0826 100644
--- a/app/models/chouette/stop_area.rb
+++ b/app/models/chouette/stop_area.rb
@@ -40,12 +40,20 @@ module Chouette
validates_format_of :url, :with => %r{\Ahttps?:\/\/([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?\Z}, :allow_nil => true, :allow_blank => true
validates_numericality_of :waiting_time, greater_than_or_equal_to: 0, only_integer: true, if: :waiting_time
+ validate :parent_area_type_must_be_greater
def self.nullable_attributes
[:registration_number, :street_name, :country_code, :fare_code,
:nearest_topic_name, :comment, :long_lat_type, :zip_code, :city_name, :url, :time_zone]
end
+ def parent_area_type_must_be_greater
+ return unless self.parent
+ if Chouette::AreaType.find(self.area_type) > Chouette::AreaType.find(self.parent.area_type)
+ errors.add(:parent_id, I18n.t('stop_areas.errors.parent_area_type', area_type: self.parent.area_type))
+ end
+ end
+
after_update :clean_invalid_access_links
before_save :coordinates_to_lat_lng