aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2017-07-17 12:03:32 +0200
committerTeddy Wing2017-07-21 15:59:53 +0200
commitac03cfc3b24c49b952a31f84cf7063a9cd68acc4 (patch)
treea0ed3dcf29bd376ceb06c4f6251a11b6de9c8e1c
parent92d1abd1ef31a357260b5cb629dfed9559dd53fb (diff)
downloadchouette-core-ac03cfc3b24c49b952a31f84cf7063a9cd68acc4.tar.bz2
VehicleJourneyAtStop: Validate day offsets are not greater than 1 day
We want to ensure day offsets can only be used to make at-stops for the current day and the next day. Any more days are declared to be invalid. For now, with bus and rail modes of transportation, we don't plan on having journeys that extend beyond a day after the initial departure. Also prevent setting negative day offsets while we're at it because it goes in the same validation block and we should allow have those. Refs #3597
-rw-r--r--app/models/chouette/vehicle_journey_at_stop.rb11
-rw-r--r--spec/models/chouette/vehicle_journey_at_stop_spec.rb15
2 files changed, 26 insertions, 0 deletions
diff --git a/app/models/chouette/vehicle_journey_at_stop.rb b/app/models/chouette/vehicle_journey_at_stop.rb
index 5dfec8352..c569e5849 100644
--- a/app/models/chouette/vehicle_journey_at_stop.rb
+++ b/app/models/chouette/vehicle_journey_at_stop.rb
@@ -3,6 +3,8 @@ module Chouette
include ForBoardingEnumerations
include ForAlightingEnumerations
+ DAY_OFFSET_MAX = 1
+
# FIXME http://jira.codehaus.org/browse/JRUBY-6358
self.primary_key = "id"
@@ -24,6 +26,15 @@ module Chouette
end
end
+ validates :arrival_day_offset, numericality: {
+ greater_than_or_equal_to: 0,
+ less_than_or_equal_to: DAY_OFFSET_MAX
+ }
+ validates :departure_day_offset, numericality: {
+ greater_than_or_equal_to: 0,
+ less_than_or_equal_to: DAY_OFFSET_MAX
+ }
+
after_initialize :set_virtual_attributes
def set_virtual_attributes
@_destroy = false
diff --git a/spec/models/chouette/vehicle_journey_at_stop_spec.rb b/spec/models/chouette/vehicle_journey_at_stop_spec.rb
new file mode 100644
index 000000000..f0b34d77a
--- /dev/null
+++ b/spec/models/chouette/vehicle_journey_at_stop_spec.rb
@@ -0,0 +1,15 @@
+require 'spec_helper'
+
+RSpec.describe Chouette::VehicleJourneyAtStop, type: :model do
+ it do
+ should validate_numericality_of(:arrival_day_offset)
+ .is_greater_than_or_equal_to(0)
+ .is_less_than_or_equal_to(Chouette::VehicleJourneyAtStop::DAY_OFFSET_MAX)
+ end
+
+ it do
+ should validate_numericality_of(:departure_day_offset)
+ .is_greater_than_or_equal_to(0)
+ .is_less_than_or_equal_to(Chouette::VehicleJourneyAtStop::DAY_OFFSET_MAX)
+ end
+end