diff options
| author | Teddy Wing | 2018-03-12 15:25:50 +0100 |
|---|---|---|
| committer | Teddy Wing | 2018-03-14 16:38:40 +0100 |
| commit | 33c2dad6ba2483a4c71d7248979bf9d82a65f234 (patch) | |
| tree | 20a119ff082c2bc58b190d1394dea73e2526a4e7 /lib/tom_tom/batch.rb | |
| parent | e558625cd5e3cad60757a537320eb15f1c045cd0 (diff) | |
| download | chouette-core-33c2dad6ba2483a4c71d7248979bf9d82a65f234.tar.bz2 | |
TomTom::Batch: Extract code to `#extract_costs_to_way_costs!`
Extract some code from `#batch` to allow us to test the part that takes
distance and time values from the response JSON and put fill them into
`WayCost`s.
In order for the test to work, had to add an `#==` method to `WayCost`
and make `distance` and `time` accessors.
The JSON file fixture is a copy of a response from the TomTom `/batch`
API. The file is pretty big. I'm not sure if maybe I should condense it
for the sake of test performance.
Refs #6095
Diffstat (limited to 'lib/tom_tom/batch.rb')
| -rw-r--r-- | lib/tom_tom/batch.rb | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/tom_tom/batch.rb b/lib/tom_tom/batch.rb index 913f018b5..6ceb9c226 100644 --- a/lib/tom_tom/batch.rb +++ b/lib/tom_tom/batch.rb @@ -23,9 +23,14 @@ module TomTom }.to_json end - response = JSON.parse(response.body) + extract_costs_to_way_costs!( + way_costs, + JSON.parse(response.body) + ) + end - calculated_routes = response['batchItems'] + def extract_costs_to_way_costs!(way_costs, batch_json) + calculated_routes = batch_json['batchItems'] calculated_routes.each_with_index do |route, i| next if route['statusCode'] != 200 |
