aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2017-05-30 15:48:09 +0200
committerTeddy Wing2017-05-31 17:57:36 +0200
commitd22ee707c026a71dac64da792cb22f46a1a1dbde (patch)
tree71c50447ed424f156f7c74d386ab07ddad141e3b
parent6f7ad36f3b958a719a8f39c75749a641ace189c5 (diff)
downloadchouette-core-d22ee707c026a71dac64da792cb22f46a1a1dbde.tar.bz2
VehicleJourneyAtStopsDayOffset: Restructure methods for persistence
The `#calculate!` method didn't actually save anything to the database. Deciding to keep the `!` because it does modify the object's internal at-stops. I didn't call an update on the at-stop objects in `#calculate!` on purpose as I wanted to avoid hitting the database in the tests to try to keep them from getting too much slower than they already are. But, we need to be able to persist the day_offset values when this class gets integrated. To do so, adding an `#update` method that will run the calculation function and update the objects in the database. Split out the actual updating into a new `#save` method because that seems logically separate. Decided not to test these two methods as the real work we care about is in `#calculate!`. Refs #3596
-rw-r--r--app/models/chouette/vehicle_journey_at_stops_day_offset.rb13
1 files changed, 11 insertions, 2 deletions
diff --git a/app/models/chouette/vehicle_journey_at_stops_day_offset.rb b/app/models/chouette/vehicle_journey_at_stops_day_offset.rb
index 490b22499..71eb46b19 100644
--- a/app/models/chouette/vehicle_journey_at_stops_day_offset.rb
+++ b/app/models/chouette/vehicle_journey_at_stops_day_offset.rb
@@ -4,8 +4,6 @@ module Chouette
@at_stops = at_stops
end
- # def update
-
def calculate!
start_date = @at_stops.first.arrival_time.to_date
offset = 0
@@ -55,5 +53,16 @@ module Chouette
previous_at_stop = at_stop
end
end
+
+ def save
+ @at_stops.each do |at_stop|
+ at_stop.save
+ end
+ end
+
+ def update
+ calculate!
+ save
+ end
end
end