diff options
| author | Teddy Wing | 2017-06-23 11:27:20 +0200 |
|---|---|---|
| committer | Teddy Wing | 2017-06-23 11:27:20 +0200 |
| commit | 0b40fcc1328fc8ed242ebad436fede48447e87aa (patch) | |
| tree | 6efe5c87008db211f65e7522a73b9ae838245f5f | |
| parent | a96c4bc40b11baf04d95c125aeb53930f64438a3 (diff) | |
| download | chouette-core-0b40fcc1328fc8ed242ebad436fede48447e87aa.tar.bz2 | |
VehicleJourney.where_departure_time_between: Make end time inclusive
When filtering vehicle journeys by departure time range, include
journeys whose departure times are equal to the end time of the range.
Turns out I made a mistake when copying the range from
`VehicleJourneysController#ransack_periode_filter`. (Here's what it
looked like: 83f143174002ea8d2758d3a3f79fa1b16be9e9eb
between = [:departure_time_gteq, :departure_time_lteq].map do |filter|
)
Add back in the `<=` to the filter.
Refs #3846
| -rw-r--r-- | app/models/chouette/vehicle_journey.rb | 2 | ||||
| -rw-r--r-- | spec/models/chouette/vehicle_journey_spec.rb | 29 |
2 files changed, 30 insertions, 1 deletions
diff --git a/app/models/chouette/vehicle_journey.rb b/app/models/chouette/vehicle_journey.rb index 44dd85864..3a5851310 100644 --- a/app/models/chouette/vehicle_journey.rb +++ b/app/models/chouette/vehicle_journey.rb @@ -256,7 +256,7 @@ module Chouette .where( %Q( "vehicle_journey_at_stops"."departure_time" >= ? - AND "vehicle_journey_at_stops"."departure_time" < ? + AND "vehicle_journey_at_stops"."departure_time" <= ? #{ if allow_empty 'OR "vehicle_journey_at_stops"."id" IS NULL' diff --git a/spec/models/chouette/vehicle_journey_spec.rb b/spec/models/chouette/vehicle_journey_spec.rb index 5a142d65d..599efe683 100644 --- a/spec/models/chouette/vehicle_journey_spec.rb +++ b/spec/models/chouette/vehicle_journey_spec.rb @@ -404,6 +404,35 @@ describe Chouette::VehicleJourney, :type => :model do .to_a ).to eq([journey]) end + + it "uses an inclusive range" do + journey_early = create( + :vehicle_journey, + stop_departure_time: '03:00:00' + ) + + route = journey_early.route + journey_pattern = journey_early.journey_pattern + + journey_late = create( + :vehicle_journey, + route: route, + journey_pattern: journey_pattern, + stop_departure_time: '04:00:00' + ) + + expect(route + .vehicle_journeys + .select('DISTINCT "vehicle_journeys".*') + .joins(' + LEFT JOIN "vehicle_journey_at_stops" + ON "vehicle_journey_at_stops"."vehicle_journey_id" = + "vehicle_journeys"."id" + ') + .where_departure_time_between('03:00', '04:00', allow_empty: true) + .to_a + ).to eq([journey_early, journey_late]) + end end describe ".without_time_tables" do |
