aboutsummaryrefslogtreecommitdiffstats
path: root/spec/lib
diff options
context:
space:
mode:
authorTeddy Wing2018-03-15 17:18:09 +0100
committerTeddy Wing2018-03-15 17:44:22 +0100
commit18bf033af20f883e92a4f05bbba5070d70fe9d90 (patch)
tree2364e7b05c435e8e6f9668019cf8875554e43a97 /spec/lib
parent7fb536325c19e837d10707e9adfc0d8bce5a3976 (diff)
downloadchouette-core-18bf033af20f883e92a4f05bbba5070d70fe9d90.tar.bz2
Rename `RouteWayCostJSONSerializer` to `RouteWayCostUnitConverter`
Because we need to pass a Ruby hash to Rabl instead of a JSON string, get rid of our serialiser and instead turn it into a function that just converts the distance & time units. Fix a bug in the test that had the `'1-2'` key as a symbol instead of a string which was caused by a copy-paste from JSON and not being thorough enough in search-and-replace. Refs #6203
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/route_way_cost_json_serializer_spec.rb31
-rw-r--r--spec/lib/route_way_cost_unit_converter_spec.rb29
2 files changed, 29 insertions, 31 deletions
diff --git a/spec/lib/route_way_cost_json_serializer_spec.rb b/spec/lib/route_way_cost_json_serializer_spec.rb
deleted file mode 100644
index 52cb21afc..000000000
--- a/spec/lib/route_way_cost_json_serializer_spec.rb
+++ /dev/null
@@ -1,31 +0,0 @@
-RSpec.describe RouteWayCostJSONSerializer do
- describe ".dump" do
- it "converts distance from meters to km and time from seconds to minutes" do
- costs = {
- '1-2': {
- 'distance' => 35223,
- 'time' => 5604
- },
- '94435-97513' => {
- 'distance' => 35919,
- 'time' => 6174
- }
- }
-
- expect(
- RouteWayCostJSONSerializer.dump(costs)
- ).to eq(<<-JSON.delete(" \n"))
- {
- "1-2": {
- "distance": 35.223,
- "time": 93
- },
- "94435-97513": {
- "distance": 35.919,
- "time": 102
- }
- }
- JSON
- end
- end
-end
diff --git a/spec/lib/route_way_cost_unit_converter_spec.rb b/spec/lib/route_way_cost_unit_converter_spec.rb
new file mode 100644
index 000000000..33fb1d9aa
--- /dev/null
+++ b/spec/lib/route_way_cost_unit_converter_spec.rb
@@ -0,0 +1,29 @@
+RSpec.describe RouteWayCostUnitConverter do
+ describe ".convert" do
+ it "converts distance from meters to km and time from seconds to minutes" do
+ costs = {
+ '1-2' => {
+ 'distance' => 35223,
+ 'time' => 5604
+ },
+ '94435-97513' => {
+ 'distance' => 35919,
+ 'time' => 6174
+ }
+ }
+
+ expect(
+ RouteWayCostUnitConverter.convert(costs)
+ ).to eq({
+ '1-2' => {
+ 'distance' => 35.223,
+ 'time' => 93
+ },
+ '94435-97513' => {
+ 'distance' => 35.919,
+ 'time' => 102
+ }
+ })
+ end
+ end
+end