| Age | Commit message (Collapse) | Author | 
 | 
Previously, the `#exceeds_gap?` method would modulo the
`later - earlier` duration against 24 hours such that no duration
exceeded 24 hours, and the resulting duration being compared was
adjusted to fit inside a single day.
When we removed the numbers from `exceeds_gap?`, we also removed the
modulo operation. I had a feeling that would potentially cause problems,
and it turns out it did. Though it still took too much investigation
time to realise that the most obvious answer was in fact the correct
one. Blame the confusing test failures if I will:
    Failures:
      1) Chouette::VehicleJourney state_update should return errors when validation failed
         Failure/Error: expect(state['errors'][:vehicle_journey_at_stops].size).to eq 1
         NoMethodError:
           undefined method `[]' for nil:NilClass
         # ./spec/models/chouette/vehicle_journey_spec.rb:148:in `block (3 levels) in <top (required)>'
      2) Chouette::VehicleJourney state_update vehicle_journey_at_stops should return errors when validation failed
         Failure/Error: expect(item['errors'][:arrival_time].size).to eq 1
         NoMethodError:
           undefined method `[]' for nil:NilClass
         # ./spec/models/chouette/vehicle_journey_spec.rb:189:in `block (4 levels) in <top (required)>'
      3) VehicleJourneyImport.save should not import vehicle_journeys and not create objects when vehicle journey at stops are not in ascendant order
         Failure/Error: expect(VehicleJourneyImport.new(:route => route, :file => invalid_file_on_vjas_object).save).to be_falsey
           expected: falsey value
                got: true
         # ./spec/models/vehicle_journey_import_spec.rb:90:in `block (3 levels) in <top (required)>'
    Finished in 4 minutes 20.7 seconds (files took 14.47 seconds to load)
    1089 examples, 3 failures, 23 pending
    Failed examples:
    rspec ./spec/models/chouette/vehicle_journey_spec.rb:137 # Chouette::VehicleJourney state_update should return errors when validation failed
    rspec ./spec/models/chouette/vehicle_journey_spec.rb:183 # Chouette::VehicleJourney state_update vehicle_journey_at_stops should return errors when validation failed
    rspec ./spec/models/vehicle_journey_import_spec.rb:89 # VehicleJourneyImport.save should not import vehicle_journeys and not create objects when vehicle journey at stops are not in ascendant order
These three tests failed with my version of `exceeds_gap?`.
To correct the failures, add back in the 24-hour adjustment. Put it in a
named method that is hopefully clear enough to understand.
The second test failure ("vehicle_journey_at_stops should return errors
when validation failed") used two times that were the same. I decided to
add a test for this because it seemed like an interesting edge case. The
test I added didn't fail even for the previous version of
`.exceeds_gap?`, but I figure it seems like a useful test anyway.
Refs #870
 | 
 | 
Describe what's going on here to hopefully make it easier to understand.
Refs #870
 | 
 | 
Instead of hard-coding the duration to compare against, get it from the
function argument. This allows us to set different durations at the time
the method is called.
Also simplify the comparison, getting rid of the math that makes this
method much more difficult to read.
Refs #870
 | 
 | 
Put the `exceeds_gap?` method in a new module called `TimeDuration`.
This will allow us to use it from both the
`Chouette::VehicleJourneyAtStop` class and from the
`IncreasingTimeOrderValidator`. Doing this also allows us to test it
independently.
Haven't yet rewritten the increasing times validator to take advantage
of this new method, but adding it now to ensure we don't get an error
calling a non-existent method in `VehicleJourneyAtStop`.
I changed the signature of the method to take a duration as its first
argument. This allows us to set arbitrary durations to compare against
and surfaces the duration when reading code where the  method is called.
Not sure if that's the best approach here, but it seems to make sense
for now.
Refs #870
 |