aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlban Peignier2018-01-11 14:30:31 +0100
committerAlban Peignier2018-01-11 14:30:31 +0100
commitd1b6592497f365d5982be84085fa8dabfd4a6b1b (patch)
treedf04dcee64031faba28d75112fddfe4602819d2a
parent3d41c249caf263adc79d099a412e2f1cbe90d064 (diff)
downloadchouette-core-d1b6592497f365d5982be84085fa8dabfd4a6b1b.tar.bz2
Prevent errors in RoutingConstraintZone when no route is defined (required no route in Referential). Refs #5552
-rw-r--r--app/models/chouette/routing_constraint_zone.rb6
1 files changed, 5 insertions, 1 deletions
diff --git a/app/models/chouette/routing_constraint_zone.rb b/app/models/chouette/routing_constraint_zone.rb
index fcf47f154..1847f6e25 100644
--- a/app/models/chouette/routing_constraint_zone.rb
+++ b/app/models/chouette/routing_constraint_zone.rb
@@ -7,7 +7,7 @@ module Chouette
belongs_to :route
has_array_of :stop_points, class_name: 'Chouette::StopPoint'
- validates_presence_of :name, :stop_points, :route
+ validates_presence_of :name, :stop_points, :route, :route_id
# validates :stop_point_ids, length: { minimum: 2, too_short: I18n.t('activerecord.errors.models.routing_constraint_zone.attributes.stop_points.not_enough_stop_points') }
validate :stop_points_belong_to_route, :not_all_stop_points_selected
@@ -29,10 +29,14 @@ module Chouette
end
def stop_points_belong_to_route
+ return unless route
+
errors.add(:stop_point_ids, I18n.t('activerecord.errors.models.routing_constraint_zone.attributes.stop_points.stop_points_not_from_route')) unless stop_points.all? { |sp| route.stop_points.include? sp }
end
def not_all_stop_points_selected
+ return unless route
+
errors.add(:stop_point_ids, I18n.t('activerecord.errors.models.routing_constraint_zone.attributes.stop_points.all_stop_points_selected')) if stop_points.length == route.stop_points.length
end