aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorZog2018-02-26 12:07:22 +0100
committerAlban Peignier2018-03-14 15:32:39 +0100
commit8aa258ab7bea85e423ed98b4d864ba7ab5481c13 (patch)
tree4868a91d8139133f91e721d3fbc1383f490ffd08 /spec
parent8abcd5a71a29f987c20f513f622ade7eced82176 (diff)
downloadchouette-core-8aa258ab7bea85e423ed98b4d864ba7ab5481c13.tar.bz2
Refs #6021 @1h; Allow journeys to span over 3 days
And fix the way offsets are computed to use the timezones
Diffstat (limited to 'spec')
-rw-r--r--spec/models/chouette/vehicle_journey_at_stops_day_offset_spec.rb71
1 files changed, 71 insertions, 0 deletions
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
index 69a2d5cb9..91cbf9097 100644
--- a/spec/models/chouette/vehicle_journey_at_stops_day_offset_spec.rb
+++ b/spec/models/chouette/vehicle_journey_at_stops_day_offset_spec.rb
@@ -86,5 +86,76 @@ describe Chouette::VehicleJourneyAtStop do
expect(at_stops[3].arrival_day_offset).to eq(2)
expect(at_stops[3].departure_day_offset).to eq(2)
end
+
+ context "with stops in a different timezone" do
+ before do
+ allow_any_instance_of(Chouette::VehicleJourneyAtStop).to receive(:local_time).and_wrap_original {|m, t| m.call(t - 12.hours)}
+ end
+
+ it "should apply the TZ" do
+ at_stops = []
+ [
+ ['22:30', '22:35'],
+ ['01:02', '01:14'],
+ ['12:02', '12:14'],
+ ].each do |arrival_time, departure_time|
+ at_stops << build_stubbed(
+ :vehicle_journey_at_stop,
+ arrival_time: arrival_time,
+ departure_time: departure_time
+ )
+ 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(0)
+
+ expect(at_stops[2].arrival_day_offset).to eq(1)
+ expect(at_stops[2].departure_day_offset).to eq(1)
+ end
+ end
+
+ context "with stops in different timezones" do
+
+ it "should apply the TZ" do
+ at_stops = []
+
+ stop_area = create(:stop_area, time_zone: "Atlantic Time (Canada)")
+ stop_point = create(:stop_point, stop_area: stop_area)
+ vehicle_journey_at_stop = build_stubbed(
+ :vehicle_journey_at_stop,
+ stop_point: stop_point,
+ arrival_time: '09:00',
+ departure_time: '09:05'
+ )
+
+ at_stops << vehicle_journey_at_stop
+
+ stop_area = create(:stop_area, time_zone: "Paris")
+ stop_point = create(:stop_point, stop_area: stop_area)
+ vehicle_journey_at_stop = build_stubbed(
+ :vehicle_journey_at_stop,
+ stop_point: stop_point,
+ arrival_time: '05:00',
+ departure_time: '05:05'
+ )
+ at_stops << vehicle_journey_at_stop
+
+ 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(1)
+ expect(at_stops[1].departure_day_offset).to eq(1)
+ end
+ end
end
end