aboutsummaryrefslogtreecommitdiffstats
path: root/lib/sql
diff options
context:
space:
mode:
authorTeddy Wing2017-05-23 17:53:01 +0200
committerRobert2017-05-29 08:49:52 +0200
commit3a89c7495894912cfac7b56913ce2465b5314ec6 (patch)
treea7465aa4bf7393f654f1a2c29638d050249e53af /lib/sql
parent6df80378d2a8977c317fd93656599d3b70cf120b (diff)
downloadchouette-core-3a89c7495894912cfac7b56913ce2465b5314ec6.tar.bz2
IncreasingTimeOrderValidator: Remove TODO
Deciding not to do this. I tried, but it didn't work. Ultimately I decided it wasn't worth it to figure out where I was going wrong as it looks readable now that there's aerated whitespace and this appears to be the only place we do this kind of thing. For the curious, here's what I tried: diff --git a/app/models/chouette/vehicle_journey_at_stop.rb b/app/models/chouette/vehicle_journey_at_stop.rb index be69de0e..538ca123 100644 --- a/app/models/chouette/vehicle_journey_at_stop.rb +++ b/app/models/chouette/vehicle_journey_at_stop.rb @@ -26,6 +26,12 @@ module Chouette @_destroy = false end + def self.select_with_departure_and_arrival_times + self.select do |vjas| + vjas.departure_time && vjas.arrival_time + end + end + def increasing_times_validate( previous) result = true return result unless previous diff --git a/app/models/chouette/vehicle_journey_at_stops_are_in_increasing_time_order_validator.rb b/app/models/chouette/vehicle_journey_at_stops_are_in_increasing_time_order_validator.rb index 3ec24ddd..d5bbb72c 100644 --- a/app/models/chouette/vehicle_journey_at_stops_are_in_increasing_time_order_validator.rb +++ b/app/models/chouette/vehicle_journey_at_stops_are_in_increasing_time_order_validator.rb @@ -9,10 +9,9 @@ module Chouette # TODO: Rename `previous` previous = nil - # TODO: Move `select` to a new named method vehicle_journey .vehicle_journey_at_stops - .select { |vjas| vjas.departure_time && vjas.arrival_time } + .select_with_departure_and_arrival_times .each do |vjas| unless vjas.increasing_times_validate(previous) vehicle_journey.errors.add( diff --git a/spec/models/chouette/vehicle_journey_at_stop_spec.rb b/spec/models/chouette/vehicle_journey_at_stop_spec.rb index ba5b2bf7..b8619e7d 100644 --- a/spec/models/chouette/vehicle_journey_at_stop_spec.rb +++ b/spec/models/chouette/vehicle_journey_at_stop_spec.rb @@ -1,10 +1,28 @@ require 'spec_helper' describe Chouette::VehicleJourneyAtStop, :type => :model do - let!(:vehicle_journey) { create(:vehicle_journey_odd)} - subject { vehicle_journey.vehicle_journey_at_stops.first } + describe ".select_with_departure_and_arrival_times" do + it "selects objects where departure_time & arrival_time are present" do + vehicle_journey = create(:vehicle_journey) + + expect( + vehicle_journey.vehicle_journey_at_stops.select_with_departure_and_arrival_times + ).to match_array(vehicle_journey.vehicle_journey_at_stops.to_a) + end + + it "doesn't select objects with no departure_time or arrival_time" do + vehicle_journey = create(:vehicle_journey_empty) + + expect( + vehicle_journey.vehicle_journey_at_stops.select_with_departure_and_arrival_times + ).to eq(Chouette::VehicleJourneyAtStop.none) + end + end describe "#exceeds_gap?" do + let!(:vehicle_journey) { create(:vehicle_journey_odd)} + subject { vehicle_journey.vehicle_journey_at_stops.first } + it "should return false if gap < 1.hour" do t1 = Time.now t2 = Time.now + 3.minutes @@ -18,6 +36,9 @@ describe Chouette::VehicleJourneyAtStop, :type => :model do end describe "#increasing_times_validate" do + let!(:vehicle_journey) { create(:vehicle_journey_odd)} + subject { vehicle_journey.vehicle_journey_at_stops.first } + let(:vjas1){ vehicle_journey.vehicle_journey_at_stops[0]} let(:vjas2){ vehicle_journey.vehicle_journey_at_stops[1]} context "when vjas#arrival_time exceeds gap" do Refs #870
Diffstat (limited to 'lib/sql')
0 files changed, 0 insertions, 0 deletions