aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/chouette/stop_area.rb
diff options
context:
space:
mode:
authorZog2018-01-29 08:45:02 +0100
committerZog2018-01-29 08:45:02 +0100
commit05bc96db48a0a84fd2c50e457dc767f88950a9b4 (patch)
treeabff83921023a3f697e8ab1e3c064dd2150fc35b /app/models/chouette/stop_area.rb
parent22c38fb750843f0c74996175a6bd17a1f20a943c (diff)
downloadchouette-core-05bc96db48a0a84fd2c50e457dc767f88950a9b4.tar.bz2
Refs #5750 @1h; Manage non-commercial StopAreas
- Add a `kind` attribute - Hide irrelevant fields in the form
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 d270a8696..75a4a34bb 100644
--- a/app/models/chouette/stop_area.rb
+++ b/app/models/chouette/stop_area.rb
@@ -32,6 +32,7 @@ module Chouette
validates_format_of :registration_number, :with => %r{\A[\d\w_\-]+\Z}, :allow_blank => true
validates_presence_of :name
+ validates_presence_of :kind
validates_presence_of :latitude, :if => :longitude
validates_presence_of :longitude, :if => :latitude
validates_numericality_of :latitude, :less_than_or_equal_to => 90, :greater_than_or_equal_to => -90, :allow_nil => true
@@ -42,6 +43,7 @@ module Chouette
validates_numericality_of :waiting_time, greater_than_or_equal_to: 0, only_integer: true, if: :waiting_time
validate :parent_area_type_must_be_greater
+ validate :area_type_of_right_kind
def self.nullable_attributes
[:registration_number, :street_name, :country_code, :fare_code,
@@ -57,6 +59,12 @@ module Chouette
end
end
+ def area_type_of_right_kind
+ unless Chouette::AreaType.send(self.kind).include?(self.area_type)
+ errors.add(:area_type, I18n.t('stop_areas.errors.incorrect_kind_area_type'))
+ end
+ end
+
after_update :clean_invalid_access_links
before_save :coordinates_to_lat_lng