aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2017-05-04 17:01:31 +0200
committerTeddy Wing2017-05-04 17:11:00 +0200
commit32bc450f332b457ce7aca208a332876672df1bc1 (patch)
treede2d8eec52946a4133160d787884cc0a8565ccbe
parent48b9ab1d9db508b658f0fee9b492bc058d99ab31 (diff)
downloadchouette-core-32bc450f332b457ce7aca208a332876672df1bc1.tar.bz2
vehicle_journey_spec.rb: #with_stops should sort journeys missing stops
If a journey is missing one or more stops at the beginning of the route, it should be sorted by the first stop it stops at. Given these journeys: | 1 | 2 | 3 -------+-------+-------+------ Stop 1 | 10:00 | | 10:15 Stop 2 | 10:10 | 10:12 | 10:25 Stop 3 | 10:20 | 10:18 | 10:35 Journey should appear in between 1 and 3 because its first stop is between 10:00 and 10:15. Move the `initialize_stop_times` helper function outside of the first test in this `describe` so we can use it again in this test. Refs #3268
-rw-r--r--spec/models/chouette/vehicle_journey_spec.rb51
1 files changed, 40 insertions, 11 deletions
diff --git a/spec/models/chouette/vehicle_journey_spec.rb b/spec/models/chouette/vehicle_journey_spec.rb
index 9a1a55a02..b22183ab6 100644
--- a/spec/models/chouette/vehicle_journey_spec.rb
+++ b/spec/models/chouette/vehicle_journey_spec.rb
@@ -222,18 +222,18 @@ describe Chouette::VehicleJourney, :type => :model do
end
describe ".with_stops" do
- it "selects vehicle journeys including stops in order or earliest departure time" do
- def initialize_stop_times(vehicle_journey, &block)
- vehicle_journey
- .vehicle_journey_at_stops
- .each_with_index do |at_stop, index|
- at_stop.update(
- departure_time: at_stop.departure_time + block.call(index),
- arrival_time: at_stop.arrival_time + block.call(index)
- )
- end
- end
+ def initialize_stop_times(vehicle_journey, &block)
+ vehicle_journey
+ .vehicle_journey_at_stops
+ .each_with_index do |at_stop, index|
+ at_stop.update(
+ departure_time: at_stop.departure_time + block.call(index),
+ arrival_time: at_stop.arrival_time + block.call(index)
+ )
+ end
+ end
+ it "selects vehicle journeys including stops in order or earliest departure time" do
# Create later vehicle journey to give it a later id, such that it should
# appear last if the order in the query isn't right.
journey_late = create(:vehicle_journey)
@@ -279,6 +279,35 @@ describe Chouette::VehicleJourney, :type => :model do
.to_a
).to eq(expected_journey_order)
end
+
+ it "journeys that skip the first stop(s) get ordered by the time of the \
+ first stop that they make" do
+ journey_missing_stop = create(:vehicle_journey)
+ journey_early = create(
+ :vehicle_journey,
+ route: journey_missing_stop.route,
+ journey_pattern: journey_missing_stop.journey_pattern
+ )
+
+ initialize_stop_times(journey_early) do |index|
+ (index + 5).minutes
+ end
+ initialize_stop_times(journey_missing_stop) do |index|
+ (index + 65).minutes
+ end
+
+ journey_missing_stop.vehicle_journey_at_stops.first.destroy
+
+ expected_journey_order = [journey_early, journey_missing_stop]
+
+ expect(
+ journey_missing_stop
+ .route
+ .vehicle_journeys
+ .with_stops
+ .to_a
+ ).to eq(expected_journey_order)
+ end
end
subject { create(:vehicle_journey_odd) }