aboutsummaryrefslogtreecommitdiffstats
path: root/spec/models
diff options
context:
space:
mode:
authorMarc Florisson2012-07-06 16:45:42 +0200
committerMarc Florisson2012-07-06 16:45:42 +0200
commita94b6b696990fd038cc425ed93f6971c1093e8cf (patch)
treeb3f1c76361cf124cf8098e61f9f7e23dd53c4b96 /spec/models
parent9758efc6d12d8dd2e38a43aa0103ce2a38e27ffd (diff)
downloadchouette-core-a94b6b696990fd038cc425ed93f6971c1093e8cf.tar.bz2
fix Refs #88, Refs #85, Refs #82
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/vehicle_translation_spec.rb60
1 files changed, 60 insertions, 0 deletions
diff --git a/spec/models/vehicle_translation_spec.rb b/spec/models/vehicle_translation_spec.rb
new file mode 100644
index 000000000..2a9c53371
--- /dev/null
+++ b/spec/models/vehicle_translation_spec.rb
@@ -0,0 +1,60 @@
+require 'spec_helper'
+
+describe VehicleTranslation do
+ let!(:company){ Factory(:company )}
+ let!(:journey_pattern){Factory(:journey_pattern)}
+ let!(:vehicle_journey){ Factory(:vehicle_journey,
+ :objectid => "dummy",
+ :journey_pattern => journey_pattern,
+ :route => journey_pattern.route,
+ :company => company,
+ :transport_mode => Chouette::TransportMode.new("metro"),
+ :published_journey_name => "dummy"
+ )}
+ subject {Factory.build(:vehicle_translation, :vehicle_journey_id => vehicle_journey.id)}
+
+ describe "#translate" do
+ it "should add new vehicle" do
+ count_before = Chouette::VehicleJourney.count
+ subject.translate
+ count_after = Chouette::VehicleJourney.count
+ count_after.should == count_before + subject.count.to_i
+ end
+ def last_created_vehicle
+ Chouette::VehicleJourney.find( :all, :order => :creation_time).last
+ end
+ it "should add vehicle having same published_journey_name" do
+ subject.translate
+ last_created_vehicle.published_journey_name.should == vehicle_journey.published_journey_name
+ end
+ it "should add vehicle having same transport_mode" do
+ subject.translate
+ last_created_vehicle.transport_mode.should == vehicle_journey.transport_mode
+ end
+ it "should add vehicle having same journey_pattern" do
+ subject.translate
+ last_created_vehicle.journey_pattern.should == vehicle_journey.journey_pattern
+ end
+ it "should add vehicle having same route" do
+ subject.translate
+ last_created_vehicle.route.should == vehicle_journey.route
+ end
+ it "should add vehicle having same company" do
+ subject.translate
+ last_created_vehicle.company.should == vehicle_journey.company
+ end
+ it "should add vehicle with as many vehicle_journey_at_stops as on basic vehicle" do
+ subject.translate
+ last_created_vehicle.vehicle_journey_at_stops.count.should == vehicle_journey.vehicle_journey_at_stops.count
+ end
+ it "should add vehicle where vehicle_journey_at_stops are translated with #duration" do
+ read_vehicle = Chouette::VehicleJourney.find(vehicle_journey.id) # read from bd, change time values
+ subject.translate
+ last_created_vehicle.vehicle_journey_at_stops.each_with_index do |vjas, index|
+ vjas.departure_time.should == (read_vehicle.vehicle_journey_at_stops[index].departure_time + subject.duration.minutes)
+ vjas.arrival_time.should == (read_vehicle.vehicle_journey_at_stops[index].arrival_time + subject.duration.minutes)
+ end
+ end
+ end
+end
+