aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorTeddy Wing2017-05-24 11:31:34 +0200
committerTeddy Wing2017-05-26 13:20:55 +0200
commit16c9f2b445de2af540db4280bde39666101e1eb0 (patch)
treeacb823b50344eaa48829dbd24d3b73faa3a4756d /app
parentec5f85038b00f1f69c85d94a042ecdad22d4e8cf (diff)
downloadchouette-core-16c9f2b445de2af540db4280bde39666101e1eb0.tar.bz2
IncreasingTimeOrder: Make `increasing_times_validate` a class method
Making this a class method allows us to test it more easily. Previously it was attached to `Chouette::VehicleJourneyAtStop`, and the tests I copied call it on a VehicleJourneyAtStop. It seems like instantiating a Validator class is kind of a pain, or at least a bit weird, since it's for internal Rails use. So we change it to a class method. Change `#exceeds_gap?` in this class to a class method also so we can continue to call it from `.increasing_times_validate`. Eventually we'll switch to the new version in the `TimeDuration` module. Comment out the tests for `#exceeds_gap?` for now as we'll be moving those into a new spec file for `TimeDuration` Refs #870
Diffstat (limited to 'app')
-rw-r--r--app/models/chouette/vehicle_journey_at_stops_are_in_increasing_time_order_validator.rb15
1 files changed, 8 insertions, 7 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 4b2fac40a..cc32ae520 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
@@ -12,7 +12,7 @@ module Chouette
.vehicle_journey_at_stops
.select { |vjas| vjas.departure_time && vjas.arrival_time }
.each do |vjas|
- unless vjas.increasing_times_validate(previous_at_stop)
+ unless self.class.increasing_times_validate(vjas, previous_at_stop)
vehicle_journey.errors.add(
:vehicle_journey_at_stops,
'time gap overflow'
@@ -23,22 +23,23 @@ module Chouette
end
end
- def increasing_times_validate(previous_at_stop)
+ def self.increasing_times_validate(at_stop, previous_at_stop)
result = true
return result unless previous_at_stop
- if exceeds_gap?(previous_at_stop.departure_time, departure_time)
+ if self.exceeds_gap?(previous_at_stop.departure_time, at_stop.departure_time)
result = false
- errors.add( :departure_time, 'departure time gap overflow')
+ at_stop.errors.add(:departure_time, 'departure time gap overflow')
end
- if exceeds_gap?(previous_at_stop.arrival_time, arrival_time)
+ if self.exceeds_gap?(previous_at_stop.arrival_time, at_stop.arrival_time)
result = false
- errors.add( :arrival_time, 'arrival time gap overflow')
+ at_stop.errors.add(:arrival_time, 'arrival time gap overflow')
end
result
end
- def exceeds_gap?(earlier, later)
+ # TODO: Get rid of this and change to TimeDuration version
+ def self.exceeds_gap?(earlier, later)
(4 * 3600) < ((later - earlier) % (3600 * 24))
end
end