From 11894d94b6698590a9ddb37729fdd90ea081159d Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 13 Mar 2018 12:04:19 +0100 Subject: Add `WayCostCollectionJSONSerializer` A JSON serialiser for a collection of `WayCost`s. This will be used to store `WayCost`s for a `Chouette::Route` in the `Route#costs` JSON field. Refs #6095 --- .../way_cost_collection_json_serializer_spec.rb | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 spec/lib/way_cost_collection_json_serializer_spec.rb (limited to 'spec') diff --git a/spec/lib/way_cost_collection_json_serializer_spec.rb b/spec/lib/way_cost_collection_json_serializer_spec.rb new file mode 100644 index 000000000..22faf88d3 --- /dev/null +++ b/spec/lib/way_cost_collection_json_serializer_spec.rb @@ -0,0 +1,37 @@ +RSpec.describe WayCostCollectionJSONSerializer do + describe ".dump" do + it "creates a JSON hash of hashed WayCost attributes" do + way_costs = [ + 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), + distance: 5678, + time: 999, + id: '2-3' + ) + ] + + expect( + WayCostCollectionJSONSerializer.dump(way_costs) + ).to eq(<<-JSON.delete(" \n")) + { + "1-2": { + "distance": 1234, + "time": 99 + }, + "2-3": { + "distance": 5678, + "time": 999 + } + } + JSON + end + end +end -- cgit v1.2.3