diff options
| author | Alban Peignier | 2018-03-15 18:23:32 +0100 | 
|---|---|---|
| committer | Alban Peignier | 2018-03-15 18:25:30 +0100 | 
| commit | dd8b4cc13d8e052d0fac7a25569f869470198256 (patch) | |
| tree | fb97b63dc1f7c8be98b5cbce40c06ce693641b45 | |
| parent | 1a9656e9d69d598cd1239c372f1002d21ec73d09 (diff) | |
| download | chouette-core-dd8b4cc13d8e052d0fac7a25569f869470198256.tar.bz2 | |
Avoid error when distance or time cost is ignored. Refs #6203
| -rw-r--r-- | lib/route_way_cost_unit_converter.rb | 6 | ||||
| -rw-r--r-- | spec/lib/route_way_cost_unit_converter_spec.rb | 12 | 
2 files changed, 15 insertions, 3 deletions
| diff --git a/lib/route_way_cost_unit_converter.rb b/lib/route_way_cost_unit_converter.rb index 979e92b0c..45edbf538 100644 --- a/lib/route_way_cost_unit_converter.rb +++ b/lib/route_way_cost_unit_converter.rb @@ -12,10 +12,14 @@ class RouteWayCostUnitConverter    # Round to 2 decimal places to appease JavaScript validation    def self.meters_to_kilometers(num) -    (num / 1000.0).round(2) +    return 0 unless num + +    (num / 1000.0).to_i    end    def self.seconds_to_minutes(num) +    return 0 unless num +      num / 60    end  end diff --git a/spec/lib/route_way_cost_unit_converter_spec.rb b/spec/lib/route_way_cost_unit_converter_spec.rb index 624ef5052..3c5e51710 100644 --- a/spec/lib/route_way_cost_unit_converter_spec.rb +++ b/spec/lib/route_way_cost_unit_converter_spec.rb @@ -10,6 +10,10 @@ RSpec.describe RouteWayCostUnitConverter do          '94435-97513' => {            'distance' => 35919,            'time' => 6174 +        }, +        '2-3' => { +          'distance' => nil, +          'time' => nil          }        } @@ -17,12 +21,16 @@ RSpec.describe RouteWayCostUnitConverter do          RouteWayCostUnitConverter.convert(costs)        ).to eq({          '1-2' => { -          'distance' => 35.22, +          'distance' => 35,            'time' => 93          },          '94435-97513' => { -          'distance' => 35.92, +          'distance' => 35,            'time' => 102 +        }, +        '2-3' => { +          'distance' => 0, +          'time' => 0          }        })      end | 
