aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorAlban Peignier2018-03-14 15:36:22 +0100
committerGitHub2018-03-14 15:36:22 +0100
commite67f5db85a228a930f7d33b5c495b2ee80ed93bd (patch)
treed7196a61df6224b30e1a175345287f9a5d887c90 /spec
parent8abcd5a71a29f987c20f513f622ade7eced82176 (diff)
parent8f5fbe3f7fdc217be28fec416d5dbbbf4b551c7c (diff)
downloadchouette-core-e67f5db85a228a930f7d33b5c495b2ee80ed93bd.tar.bz2
Merge pull request #342 from af83/6021-handlke-offsets-in-journeys
Allow journeys to span over 3 days. Refs #6021
Diffstat (limited to 'spec')
-rw-r--r--spec/models/chouette/vehicle_journey_at_stop_spec.rb6
-rw-r--r--spec/models/chouette/vehicle_journey_at_stops_day_offset_spec.rb71
2 files changed, 74 insertions, 3 deletions
diff --git a/spec/models/chouette/vehicle_journey_at_stop_spec.rb b/spec/models/chouette/vehicle_journey_at_stop_spec.rb
index f79d19c88..ae9823243 100644
--- a/spec/models/chouette/vehicle_journey_at_stop_spec.rb
+++ b/spec/models/chouette/vehicle_journey_at_stop_spec.rb
@@ -27,13 +27,13 @@ RSpec.describe Chouette::VehicleJourneyAtStop, type: :model do
it "disallows offsets greater than DAY_OFFSET_MAX" do
expect(at_stop.day_offset_outside_range?(
- Chouette::VehicleJourneyAtStop::DAY_OFFSET_MAX + 1
+ Chouette::VehicleJourneyAtStop.day_offset_max + 1
)).to be true
end
it "allows offsets between 0 and DAY_OFFSET_MAX inclusive" do
expect(at_stop.day_offset_outside_range?(
- Chouette::VehicleJourneyAtStop::DAY_OFFSET_MAX
+ Chouette::VehicleJourneyAtStop.day_offset_max
)).to be false
end
@@ -79,7 +79,7 @@ RSpec.describe Chouette::VehicleJourneyAtStop, type: :model do
describe "#validate" do
it "displays the proper error message when day offset exceeds the max" do
- bad_offset = Chouette::VehicleJourneyAtStop::DAY_OFFSET_MAX + 1
+ bad_offset = Chouette::VehicleJourneyAtStop.day_offset_max + 1
at_stop = build_stubbed(
:vehicle_journey_at_stop,
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