aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorXinhui2017-04-04 12:42:11 +0200
committerXinhui2017-04-04 12:42:17 +0200
commit055fa0b56c0a47482f098af079b5e0929be56acd (patch)
tree42a6fcd033f9b93d79e80fea4e4348b87803bd2a /spec
parentdd9a3e95b412a635d6787553fc8e0b8fa3219754 (diff)
downloadchouette-core-055fa0b56c0a47482f098af079b5e0929be56acd.tar.bz2
Save vehicle_journey_at_stops from newly created vehicle journey
Refs #2777
Diffstat (limited to 'spec')
-rw-r--r--spec/models/chouette/vehicle_journey_spec.rb45
1 files changed, 32 insertions, 13 deletions
diff --git a/spec/models/chouette/vehicle_journey_spec.rb b/spec/models/chouette/vehicle_journey_spec.rb
index fab9cd5e8..c922731a7 100644
--- a/spec/models/chouette/vehicle_journey_spec.rb
+++ b/spec/models/chouette/vehicle_journey_spec.rb
@@ -1,23 +1,28 @@
require 'spec_helper'
describe Chouette::VehicleJourney, :type => :model do
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|
+ at_stop[att.to_s] = vjas.send(att) unless vjas.send(att).nil?
+ end
+
+ [:arrival_time, :departure_time].map do |att|
+ at_stop[att.to_s] = {
+ 'hour' => vjas.send(att).strftime('%H'),
+ 'minute' => vjas.send(att).strftime('%M'),
+ }
+ end
+ at_stop
+ end
+
def vehicle_journey_to_state vj
vj.attributes.slice('objectid', 'published_journey_name', 'journey_pattern_id', 'company_id').tap do |item|
item['vehicle_journey_at_stops'] = []
- vj.vehicle_journey_at_stops.each do |vs|
- at_stops = {'stop_area_object_id' => vs.stop_point.stop_area.objectid }
- [:id, :connecting_service_id, :boarding_alighting_possibility].map do |att|
- at_stops[att.to_s] = vs.send(att) unless vs.send(att).nil?
- end
-
- [:arrival_time, :departure_time].map do |att|
- at_stops[att.to_s] = {
- 'hour' => vs.send(att).strftime('%H'),
- 'minute' => vs.send(att).strftime('%M'),
- }
- end
- item['vehicle_journey_at_stops'] << at_stops
+ vj.vehicle_journey_at_stops.each do |vjas|
+ item['vehicle_journey_at_stops'] << vehicle_journey_at_stop_to_state(vjas)
end
end
end
@@ -40,6 +45,20 @@ describe Chouette::VehicleJourney, :type => :model do
expect(vj.published_journey_name).to eq 'dummy'
end
+ it 'should save vehicle_journey_at_stops of newly created vj' do
+ new_vj = build(:vehicle_journey, objectid: nil, published_journey_name: 'dummy', route: route, journey_pattern: journey_pattern)
+ new_vj.vehicle_journey_at_stops << build(:vehicle_journey_at_stop,
+ :vehicle_journey => new_vj,
+ :stop_point => create(:stop_point),
+ :arrival_time => '2000-01-01 01:00:00 UTC',
+ :departure_time => '2000-01-01 03:00:00 UTC')
+
+ collection << vehicle_journey_to_state(new_vj)
+ expect {
+ Chouette::VehicleJourney.state_update(route, collection)
+ }.to change {Chouette::VehicleJourneyAtStop.count}.by(1)
+ end
+
it 'should update vj journey_pattern' do
state['journey_pattern'] = create(:journey_pattern).attributes.slice('id', 'name', 'objectid')
Chouette::VehicleJourney.state_update(route, collection)