aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorTeddy Wing2017-05-22 13:44:45 +0200
committerTeddy Wing2017-05-22 13:44:45 +0200
commit9ff6f376add6ff06ccd09f9b73b8d903149c7a7b (patch)
treec75004c5be780847944e4756c9c203258111a293 /spec
parent61cffec83b8d83fd330175cd9798cecd9338e967 (diff)
downloadchouette-core-9ff6f376add6ff06ccd09f9b73b8d903149c7a7b.tar.bz2
VehicleJourney: Add #exclude_journeys_without_time_tables
A new class method that allows us to filter out vehicle journeys that aren't associated with `TimeTable`s. This is what back the filter toggle on VehicleJourneys#index for "Afficher les courses sans calendrier". Using a subquery to allow us to filter out duplicates, so we don't end up with duplicate vehicle journeys in the final result set. Then we just remove the vehicle journeys that have no entries in the `time_tables_vehicle_journeys` through table, leaving us with only the vehicle journeys that have associated calendars. Refs #3427
Diffstat (limited to 'spec')
-rw-r--r--spec/models/chouette/vehicle_journey_spec.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/spec/models/chouette/vehicle_journey_spec.rb b/spec/models/chouette/vehicle_journey_spec.rb
index 7f2305134..446eb9260 100644
--- a/spec/models/chouette/vehicle_journey_spec.rb
+++ b/spec/models/chouette/vehicle_journey_spec.rb
@@ -365,6 +365,27 @@ describe Chouette::VehicleJourney, :type => :model do
end
end
+ describe ".exclude_journeys_without_time_tables" do
+ it "filters out vehicle journeys not associated with a calendar" do
+ journey = create(:vehicle_journey)
+ route = journey.route
+
+ journey_with_time_table = create(
+ :vehicle_journey,
+ route: route,
+ journey_pattern: journey.journey_pattern
+ )
+ journey_with_time_table.time_tables << create(:time_table)
+
+ expect(
+ route
+ .vehicle_journeys
+ .exclude_journeys_without_time_tables
+ .to_a
+ ).to eq([journey_with_time_table])
+ end
+ end
+
subject { create(:vehicle_journey_odd) }
describe "in_relation_to_a_journey_pattern methods" do
let!(:route) { create(:route)}