diff options
| author | Teddy Wing | 2017-05-23 17:53:01 +0200 |
|---|---|---|
| committer | Teddy Wing | 2017-05-26 13:20:55 +0200 |
| commit | b0049feeb474045a2c298b9ee0bddbf9ea6c59b8 (patch) | |
| tree | 6931218fd1f9a84befd45288058c56e319adb6ce /app | |
| parent | 8435122816197160a3fdab89b1f178266ed2d653 (diff) | |
| download | chouette-core-b0049feeb474045a2c298b9ee0bddbf9ea6c59b8.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 'app')
| -rw-r--r-- | app/models/chouette/vehicle_journey_at_stops_are_in_increasing_time_order_validator.rb | 1 |
1 files changed, 0 insertions, 1 deletions
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 3ec24ddd9..cd43ea953 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,7 +9,6 @@ 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 } |
