aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZog2018-02-02 11:55:27 +0100
committercedricnjanga2018-02-06 11:11:32 -0800
commit0d620e6ad68ac1e1bcc393f3b87c4bf4259b2531 (patch)
treebca08f3f01d2d00a595490a232ebe9f27373d45a
parent1f38551f95bf59cef23eca5af95a71ed51056aa5 (diff)
downloadchouette-core-0d620e6ad68ac1e1bcc393f3b87c4bf4259b2531.tar.bz2
Refs 5832; Fix bug on ReferentialVehicleJourneys#index filters
By default a value was always set on the "Line" filter, yielding misleading results.
-rw-r--r--app/views/referential_vehicle_journeys/_filters.html.slim1
-rw-r--r--spec/models/chouette/vehicle_journey_spec.rb42
2 files changed, 43 insertions, 0 deletions
diff --git a/app/views/referential_vehicle_journeys/_filters.html.slim b/app/views/referential_vehicle_journeys/_filters.html.slim
index 3a9b0a4ef..d3cb9eb4b 100644
--- a/app/views/referential_vehicle_journeys/_filters.html.slim
+++ b/app/views/referential_vehicle_journeys/_filters.html.slim
@@ -23,6 +23,7 @@
.form-inline.filter_menu
= f.input :route_line_id_eq,
as: :select,
+ include_blank: t(".all"),
collection: @vehicle_journeys.lines,
selected: params[:q] && params[:q][:line_id],
input_html: { \
diff --git a/spec/models/chouette/vehicle_journey_spec.rb b/spec/models/chouette/vehicle_journey_spec.rb
index e9ffddd2a..909d6582d 100644
--- a/spec/models/chouette/vehicle_journey_spec.rb
+++ b/spec/models/chouette/vehicle_journey_spec.rb
@@ -24,6 +24,48 @@ describe Chouette::VehicleJourney, :type => :model do
it_behaves_like 'checksum support', :vehicle_journey
end
+ describe "#with_stop_area_ids" do
+ subject(:result){Chouette::VehicleJourney.with_stop_area_ids(ids)}
+ let(:ids){[]}
+ let(:common_stop_area){ create :stop_area}
+ let!(:journey_1){ create :vehicle_journey }
+ let!(:journey_2){ create :vehicle_journey }
+
+ before(:each) do
+ journey_1.journey_pattern.stop_points.last.update_attribute :stop_area_id, common_stop_area.id
+ journey_2.journey_pattern.stop_points.last.update_attribute :stop_area_id, common_stop_area.id
+ expect(journey_1.stop_areas).to include(common_stop_area)
+ expect(journey_2.stop_areas).to include(common_stop_area)
+ end
+ context "with no value" do
+ it "should return all journeys" do
+ expect(result).to eq Chouette::VehicleJourney.all
+ end
+ end
+
+ context "with a single value" do
+ let(:ids){[journey_1.stop_areas.first.id]}
+ it "should return all journeys" do
+ expect(result).to eq [journey_1]
+ end
+
+ context "with a common area" do
+ let(:ids){[common_stop_area.id]}
+ it "should return all journeys" do
+ expect(result).to eq [journey_1, journey_2]
+ end
+ end
+ end
+
+ context "with a couple of values" do
+ let(:ids){[journey_1.stop_areas.first.id, common_stop_area.id]}
+ it "should return only the matching journeys" do
+ expect(result).to eq [journey_1]
+ end
+ end
+
+ end
+
describe '#in_purchase_window' do
let(:start_date){2.month.ago.to_date}
let(:end_date){1.month.ago.to_date}