diff options
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/models/chouette/vehicle_journey_at_stops_day_offset_spec.rb | 71 |
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 |
