diff options
| author | Teddy Wing | 2017-07-21 15:13:12 +0200 |
|---|---|---|
| committer | Teddy Wing | 2017-07-21 15:59:53 +0200 |
| commit | 490c4bba551803f45f5b9a854d10e5f56e4fa480 (patch) | |
| tree | 6f91fd3f10e4537dccbeee0e9ab83f50d1605973 | |
| parent | 1dc71242b81f6bdcde4c5e093c36124011599675 (diff) | |
| download | chouette-core-490c4bba551803f45f5b9a854d10e5f56e4fa480.tar.bz2 | |
VehicleJourney: Remove 'departure time before arrival time' validation
Remove the `#vjas_departure_time_must_be_before_next_stop_arrival_time`
validation. This prevented vehicle journeys from being saved if they
contained at-stops with a day offset > 0.
For example:
Arrival | Departure
23:30 | 23:30
00:05 | 00:05
should work because 00:05 is on the next day, but it doesn't because the
validation sees it as !(23:30 < 00:05).
Luc says we should remove this validator in order for the day offsets to
work. He instructed me to comment the code instead of removing it
outright, because we're not sure yet what we want to do with this, and
he needs to look into the use-case for the validation. It could be that
we completely remove the validation method, or maybe we modify it
somewhat to play nicely with day offsets.
Skip the tests that check this validation method because we've commented
out the validation. Add a test to check that saving a vehicle journey
with a positive at-stop day offset works (it failed before commenting
out the validation). Unfortunately it seemed too complicated to use
`build_stubbed` in my new test, so I gave up and just used `create`.
Sorry test speedsters. Maybe you can refactor something more
enlightened.
Refs #3597
| -rw-r--r-- | app/models/chouette/vehicle_journey.rb | 11 | ||||
| -rw-r--r-- | spec/models/chouette/vehicle_journey_spec.rb | 19 |
2 files changed, 28 insertions, 2 deletions
diff --git a/app/models/chouette/vehicle_journey.rb b/app/models/chouette/vehicle_journey.rb index 19299d098..bc2713973 100644 --- a/app/models/chouette/vehicle_journey.rb +++ b/app/models/chouette/vehicle_journey.rb @@ -23,7 +23,10 @@ module Chouette validates_presence_of :route validates_presence_of :journey_pattern - validates :vehicle_journey_at_stops, :vjas_departure_time_must_be_before_next_stop_arrival_time, + validates :vehicle_journey_at_stops, + # Validation temporarily removed for day offsets + # :vjas_departure_time_must_be_before_next_stop_arrival_time, + vehicle_journey_at_stops_are_in_increasing_time_order: true validates_presence_of :number @@ -34,6 +37,12 @@ module Chouette before_validation :set_default_values, :calculate_vehicle_journey_at_stop_day_offset + # TODO: Remove this validator + # We've eliminated this validation because it prevented vehicle journeys + # from being saved with at-stops having a day offset greater than 0, + # because these would have times that were "earlier" than the previous + # at-stop. TBD by Luc whether we're deleting this validation altogether or + # instead rejiggering it to work with day offsets. def vjas_departure_time_must_be_before_next_stop_arrival_time notice = 'departure time must be before next stop arrival time' vehicle_journey_at_stops.each_with_index do |current_stop, index| diff --git a/spec/models/chouette/vehicle_journey_spec.rb b/spec/models/chouette/vehicle_journey_spec.rb index c495becac..645513735 100644 --- a/spec/models/chouette/vehicle_journey_spec.rb +++ b/spec/models/chouette/vehicle_journey_spec.rb @@ -1,7 +1,24 @@ require 'spec_helper' describe Chouette::VehicleJourney, :type => :model do - describe "vjas_departure_time_must_be_before_next_stop_arrival_time" do + it "must be valid with an at-stop day offset of 1" do + vehicle_journey = create( + :vehicle_journey, + stop_arrival_time: '23:00:00', + stop_departure_time: '23:00:00' + ) + vehicle_journey.vehicle_journey_at_stops.last.update( + arrival_time: '00:30:00', + departure_time: '00:30:00', + arrival_day_offset: 1, + departure_day_offset: 1 + ) + + expect(vehicle_journey).to be_valid + end + + describe "vjas_departure_time_must_be_before_next_stop_arrival_time", + skip: "Validation currently commented out because it interferes with day offsets" do let(:vehicle_journey) { create :vehicle_journey } let(:vjas) { vehicle_journey.vehicle_journey_at_stops } |
