diff options
| author | Teddy Wing | 2017-05-29 12:53:29 +0200 |
|---|---|---|
| committer | Teddy Wing | 2017-05-31 17:57:36 +0200 |
| commit | c6d622d662d7f787787d8ee3d89f5d900dd8ca59 (patch) | |
| tree | da17e5b10d053174f3b97c49feda37fcb89ae81a | |
| parent | 27cf3ff3a587c38c1fa2c5ac5048f22f38bb85e9 (diff) | |
| download | chouette-core-c6d622d662d7f787787d8ee3d89f5d900dd8ca59.tar.bz2 | |
Add a basic test to check VehicleJourneyAtStop day offsets
Create a new class that will determine the day offset of a
VehicleJourneyAtStop given a list of VehicleJourneyAtStops.
The idea is, every time midnight is passed, the day offset should be
incremented and saved in the appropriate fields of the
VehicleJourneyAtStop. No real code right now, Just committing the first
test I came up with.
The test takes a handful of at-stops and checks that they have the
correct `departure_day_offset` & `arrival_day_offset` after running our
calculation method.
Refs #3596
| -rw-r--r-- | app/models/chouette/vehicle_journey_at_stops_day_offset.rb | 13 | ||||
| -rw-r--r-- | spec/models/chouette/vehicle_journey_at_stops_day_offset_spec.rb | 46 |
2 files changed, 59 insertions, 0 deletions
diff --git a/app/models/chouette/vehicle_journey_at_stops_day_offset.rb b/app/models/chouette/vehicle_journey_at_stops_day_offset.rb new file mode 100644 index 000000000..3825fa263 --- /dev/null +++ b/app/models/chouette/vehicle_journey_at_stops_day_offset.rb @@ -0,0 +1,13 @@ +module Chouette + class VehicleJourneyAtStopsDayOffset + def initialize(at_stops) + @at_stops = at_stops + end + + # def update + + def calculate! + @at_stops + end + end +end diff --git a/spec/models/chouette/vehicle_journey_at_stops_day_offset_spec.rb b/spec/models/chouette/vehicle_journey_at_stops_day_offset_spec.rb new file mode 100644 index 000000000..f47d7dfd1 --- /dev/null +++ b/spec/models/chouette/vehicle_journey_at_stops_day_offset_spec.rb @@ -0,0 +1,46 @@ +require 'spec_helper' + +# TODO: Ensure that the fields have a default value of 0 + +describe Chouette::VehicleJourneyAtStop do + describe "#calculate" do + it "increments day offset when departure & arrival are on different sides + of midnight" do + at_stops = [] + [ + ['22:30', '22:35'], + ['23:50', '00:05'], + ['00:30', '00:35'], + ].each do |arrival_time, departure_time| + at_stops << build( + :vehicle_journey_at_stop, + arrival_time: "2000-01-01 #{arrival_time} UTC", + departure_time: "2000-01-01 #{departure_time} UTC", + + # TODO: make this the default + arrival_day_offset: 0, + departure_day_offset: 0 + ) + end + + offsetter = Chouette::VehicleJourneyAtStopsDayOffset.new(at_stops) + + offsetter.calculate! + + expect(at_stops[0].arrival_day_offset).to eq(0) + expect(at_stops[0].departure_day_offset).to eq(0) + + expect(at_stops[1].arrival_day_offset).to eq(0) + expect(at_stops[1].departure_day_offset).to eq(1) + + expect(at_stops[2].arrival_day_offset).to eq(1) + expect(at_stops[2].departure_day_offset).to eq(1) + end + + it "increments day offset when an at_stop passes midnight the next day" do + end + + it "increments day offset for multi-day offsets" do + end + end +end |
