diff options
| author | Xinhui | 2017-06-01 17:11:35 +0200 |
|---|---|---|
| committer | Xinhui | 2017-06-01 17:11:46 +0200 |
| commit | 81da8717b726e98d40e3ebf5a2a56d3a9703d8c6 (patch) | |
| tree | 0e213489f6e5b29210cca8179d8119e25cd6cda1 /spec | |
| parent | 2c2988b6ba0cf36254fdec4696da14f7103fa503 (diff) | |
| download | chouette-core-81da8717b726e98d40e3ebf5a2a56d3a9703d8c6.tar.bz2 | |
Wip validate vjas departure_time must be before next stop arrival_time
Refs #3418
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/factories/chouette_vehicle_journey.rb | 9 | ||||
| -rw-r--r-- | spec/models/chouette/vehicle_journey_spec.rb | 31 |
2 files changed, 31 insertions, 9 deletions
diff --git a/spec/factories/chouette_vehicle_journey.rb b/spec/factories/chouette_vehicle_journey.rb index 452909f23..e7ecb79ac 100644 --- a/spec/factories/chouette_vehicle_journey.rb +++ b/spec/factories/chouette_vehicle_journey.rb @@ -18,11 +18,16 @@ FactoryGirl.define do after(:create) do |vehicle_journey, evaluator| vehicle_journey.journey_pattern.stop_points.each_with_index do |stop_point, index| + prev_stop = vehicle_journey.vehicle_journey_at_stops[index - 1] + + arrival_time = prev_stop ? prev_stop[:departure_time] + 1.minute : evaluator.stop_arrival_time + departure_time = prev_stop ? arrival_time + 1.minute : evaluator.stop_departure_time + vehicle_journey.vehicle_journey_at_stops << create(:vehicle_journey_at_stop, :vehicle_journey => vehicle_journey, :stop_point => stop_point, - :arrival_time => "2000-01-01 #{evaluator.stop_arrival_time} UTC", - :departure_time => "2000-01-01 #{evaluator.stop_departure_time} UTC") + :arrival_time => "2000-01-01 #{arrival_time} UTC", + :departure_time => "2000-01-01 #{departure_time} UTC") end end diff --git a/spec/models/chouette/vehicle_journey_spec.rb b/spec/models/chouette/vehicle_journey_spec.rb index 6518e101f..f96c687f4 100644 --- a/spec/models/chouette/vehicle_journey_spec.rb +++ b/spec/models/chouette/vehicle_journey_spec.rb @@ -1,7 +1,28 @@ require 'spec_helper' + describe Chouette::VehicleJourney, :type => :model do - describe "state_update" do + describe "vjas_departure_time_must_be_before_next_stop_arrival_time" do + let(:vehicle_journey) { create :vehicle_journey } + let(:vjas) { vehicle_journey.vehicle_journey_at_stops } + + it 'should add errors a stop departure_time is greater then next stop arrival time' do + vjas[0][:departure_time] = vjas[1][:arrival_time] + 1.hour + vehicle_journey.validate + + expect(vjas[0].errors[:departure_time]).not_to be_blank + expect(vehicle_journey).not_to be_valid + end + it 'should not add errors when departure_time is less then next stop arrival time' do + vehicle_journey.validate + vjas.each do |stop| + expect(stop.errors).to be_empty + end + expect(vehicle_journey).to be_valid + end + end + + describe "state_update" do def vehicle_journey_at_stop_to_state vjas at_stop = {'stop_area_object_id' => vjas.stop_point.stop_area.objectid } [:id, :connecting_service_id, :boarding_alighting_possibility].map do |att| @@ -136,16 +157,12 @@ describe Chouette::VehicleJourney, :type => :model do it 'should return errors when validation failed' do state['published_journey_name'] = 'edited_name' - # Exceeds_gap departure time validation failed - prev = state['vehicle_journey_at_stops'].last(2).first - last = state['vehicle_journey_at_stops'].last - prev['departure_time']['hour'] = '01' - last['departure_time']['hour'] = '23' + state['vehicle_journey_at_stops'].last['departure_time']['hour'] = '23' expect { Chouette::VehicleJourney.state_update(route, collection) }.not_to change(vehicle_journey, :published_journey_name) - expect(state['errors'][:vehicle_journey_at_stops].size).to eq 1 + expect(state['vehicle_journey_at_stops'].last['errors']).not_to be_empty end it 'should delete vj with deletable set to true from state' do |
