diff options
| author | Teddy Wing | 2018-04-16 12:15:01 +0200 |
|---|---|---|
| committer | Teddy Wing | 2018-04-16 16:21:04 +0200 |
| commit | ae3933586653c00ea92d788380fc81d3586e4d42 (patch) | |
| tree | b28bebe63549df7e3ee076d14d8c0373f96428b4 | |
| parent | fc1c4b7ca5b9e2886413ddd24d5cba90ea7dd804 (diff) | |
| download | chouette-core-ae3933586653c00ea92d788380fc81d3586e4d42.tar.bz2 | |
WayCostsFromRouteCostsPopulator: Handle missing route costs
If a `Route#cost` is missing the method shouldn't fail. Instead, it
should just pass the `WayCost` along without distance & time cost
values. This way we end up with a list of all `WayCost`s for all stop
areas, even the new ones that haven't been run through the TomTom
calculator yet.
Refs #6097
| -rw-r--r-- | lib/way_costs_from_route_costs_populator.rb | 6 | ||||
| -rw-r--r-- | spec/lib/way_costs_from_route_costs_populator_spec.rb | 39 |
2 files changed, 43 insertions, 2 deletions
diff --git a/lib/way_costs_from_route_costs_populator.rb b/lib/way_costs_from_route_costs_populator.rb index 618e80366..e179df11f 100644 --- a/lib/way_costs_from_route_costs_populator.rb +++ b/lib/way_costs_from_route_costs_populator.rb @@ -8,8 +8,10 @@ class WayCostsFromRouteCostsPopulator @way_costs.map do |way_cost| route_cost = @route_costs[way_cost.id] - way_cost.distance = route_cost['distance'] - way_cost.time = route_cost['time'] + if route_cost + way_cost.distance = route_cost['distance'] + way_cost.time = route_cost['time'] + end way_cost end diff --git a/spec/lib/way_costs_from_route_costs_populator_spec.rb b/spec/lib/way_costs_from_route_costs_populator_spec.rb index b07988f38..eb9096c2c 100644 --- a/spec/lib/way_costs_from_route_costs_populator_spec.rb +++ b/spec/lib/way_costs_from_route_costs_populator_spec.rb @@ -44,5 +44,44 @@ RSpec.describe WayCostsFromRouteCostsPopulator do ) ]) end + + it "doesn't fail when `route_costs` doesn't include a WayCost" do + way_costs = [ + WayCost.new( + departure: Geokit::LatLng.new(48.85086, 2.36143), + arrival: Geokit::LatLng.new(47.91231, 1.87606), + id: '1-2' + ), + WayCost.new( + departure: Geokit::LatLng.new(47.91231, 1.87606), + arrival: Geokit::LatLng.new(52.50867, 13.42879), + id: '2-3' + ) + ] + + route_costs = { + '1-2' => { + 'distance' => 1234, + 'time' => 99 + } + } + + WayCostsFromRouteCostsPopulator.new(way_costs, route_costs).populate! + + expect(way_costs).to eq([ + WayCost.new( + departure: Geokit::LatLng.new(48.85086, 2.36143), + arrival: Geokit::LatLng.new(47.91231, 1.87606), + distance: 1234, + time: 99, + id: '1-2' + ), + WayCost.new( + departure: Geokit::LatLng.new(47.91231, 1.87606), + arrival: Geokit::LatLng.new(52.50867, 13.42879), + id: '2-3' + ) + ]) + end end end |
