Return a GPX::GPXFile object instead of a string in Points::GpxSerializer

This commit is contained in:
Eugene Burmakin 2024-11-08 16:47:20 +01:00
parent 315b022dff
commit d09a4f3305
2 changed files with 11 additions and 9 deletions

View file

@ -24,7 +24,10 @@ class Points::GpxSerializer
)
end
gpx_file.to_s.sub('<gpx', '<gpx xmlns="http://www.topografix.com/GPX/1/1"')
GPX::GPXFile.new(
name: "dawarich_#{name}",
gpx_data: gpx_file.to_s.sub('<gpx', '<gpx xmlns="http://www.topografix.com/GPX/1/1"')
)
end
private

View file

@ -4,26 +4,25 @@ require 'rails_helper'
RSpec.describe Points::GpxSerializer do
describe '#call' do
subject(:serializer) { described_class.new(points).call }
subject(:serializer) { described_class.new(points, 'some_name').call }
let(:points) { create_list(:point, 3) }
let(:geojson_data) { Points::GeojsonSerializer.new(points).call }
let(:gpx) { GPX::GeoJSON.convert_to_gpx(geojson_data:) }
it 'returns GPX file' do
expect(serializer).to be_a(GPX::GPXFile)
end
it 'includes waypoints' do
expect(serializer.waypoints.size).to eq(3)
expect(serializer.tracks[0].points.size).to eq(3)
end
it 'includes waypoints with correct attributes' do
serializer.waypoints.each_with_index do |waypoint, index|
serializer.tracks[0].points.each_with_index do |track_point, index|
point = points[index]
expect(waypoint.lat).to eq(point.latitude)
expect(waypoint.lon).to eq(point.longitude)
expect(waypoint.time).to eq(point.recorded_at)
expect(track_point.lat).to eq(point.latitude)
expect(track_point.lon).to eq(point.longitude)
expect(track_point.time).to eq(point.recorded_at)
end
end
end