aboutsummaryrefslogtreecommitdiffstats
path: root/spec/models/chouette
diff options
context:
space:
mode:
authorZog2018-01-08 11:06:20 +0100
committerZog2018-01-11 21:55:48 +0100
commitef3942099583f86d3f355a1bac8d99ce16cd2de3 (patch)
tree0519d8d4d4495da9acc7d0e02e36a2f68028c527 /spec/models/chouette
parent1fd6d7d0cfb63b024860d1c29fca089432fce2e1 (diff)
downloadchouette-core-ef3942099583f86d3f355a1bac8d99ce16cd2de3.tar.bz2
Refs #5493 @1h; Use local time in the Journeys editor
We store UTC times in the database though
Diffstat (limited to 'spec/models/chouette')
-rw-r--r--spec/models/chouette/vehicle_journey_at_stop_spec.rb24
-rw-r--r--spec/models/chouette/vehicle_journey_spec.rb30
2 files changed, 50 insertions, 4 deletions
diff --git a/spec/models/chouette/vehicle_journey_at_stop_spec.rb b/spec/models/chouette/vehicle_journey_at_stop_spec.rb
index df8a630fe..4d4a1794e 100644
--- a/spec/models/chouette/vehicle_journey_at_stop_spec.rb
+++ b/spec/models/chouette/vehicle_journey_at_stop_spec.rb
@@ -40,6 +40,30 @@ RSpec.describe Chouette::VehicleJourneyAtStop, type: :model do
end
end
+ context "the different times" do
+ let (:at_stop) { build_stubbed(:vehicle_journey_at_stop) }
+
+ describe "without a TimeZone" do
+ it "should not offset times" do
+ expect(at_stop.departure).to eq at_stop.departure_local
+ expect(at_stop.arrival).to eq at_stop.arrival_local
+ end
+ end
+
+
+ describe "with a TimeZone" do
+ before(:each) do
+ stop = at_stop.stop_point.stop_area
+ stop.time_zone = "Mexico City"
+ end
+
+ it "should offset times" do
+ expect(at_stop.departure_local).to eq at_stop.send(:format_time, at_stop.departure_time - 6.hours)
+ expect(at_stop.arrival_local).to eq at_stop.send(:format_time, at_stop.arrival_time - 6.hours)
+ end
+ end
+ end
+
describe "#validate" do
it "displays the proper error message when day offset exceeds the max" do
bad_offset = Chouette::VehicleJourneyAtStop::DAY_OFFSET_MAX + 1
diff --git a/spec/models/chouette/vehicle_journey_spec.rb b/spec/models/chouette/vehicle_journey_spec.rb
index 06cac6bc7..0beec2d81 100644
--- a/spec/models/chouette/vehicle_journey_spec.rb
+++ b/spec/models/chouette/vehicle_journey_spec.rb
@@ -64,10 +64,12 @@ describe Chouette::VehicleJourney, :type => :model do
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'),
+ at_stop["stop_point_objectid"] = vjas&.stop_point&.objectid
+
+ [:arrival, :departure].map do |att|
+ at_stop["#{att}_time"] = {
+ 'hour' => vjas.send("#{att}_local_time").strftime('%H'),
+ 'minute' => vjas.send("#{att}_local_time").strftime('%M'),
}
end
at_stop
@@ -112,6 +114,26 @@ describe Chouette::VehicleJourney, :type => :model do
expect(obj.published_journey_name).to eq 'dummy'
end
+ it 'should expect local times' do
+ new_vj = build(:vehicle_journey, objectid: nil, published_journey_name: 'dummy', route: route, journey_pattern: journey_pattern)
+ stop_area = create(:stop_area, time_zone: "Mexico City")
+ stop_point = create(:stop_point, stop_area: stop_area)
+ new_vj.vehicle_journey_at_stops << build(:vehicle_journey_at_stop, vehicle_journey: vehicle_journey, stop_point: stop_point)
+ data = vehicle_journey_to_state(new_vj)
+ data['vehicle_journey_at_stops'][0]["departure_time"]["hour"] = "15"
+ data['vehicle_journey_at_stops'][0]["arrival_time"]["hour"] = "12"
+ collection << data
+ expect {
+ Chouette::VehicleJourney.state_update(route, collection)
+ }.to change {Chouette::VehicleJourney.count}.by(1)
+ created = Chouette::VehicleJourney.last.vehicle_journey_at_stops.last
+ expect(created.stop_point).to eq stop_point
+ expect(created.departure_local_time.hour).to_not eq created.departure_time.hour
+ expect(created.arrival_local_time.hour).to_not eq created.arrival_time.hour
+ expect(created.departure_local_time.hour).to eq 15
+ expect(created.arrival_local_time.hour).to eq 12
+ 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,