From 157d916f6bfd9a1c815cfeed92c460ec824b2d85 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Wed, 22 Jan 2025 11:15:55 +0100 Subject: [PATCH] Fix a bug where a gpx file with empty tracks was not being imported --- CHANGELOG.md | 5 +++ app/services/gpx/track_parser.rb | 4 ++- spec/fixtures/files/gpx/arc_example.gpx | 41 +++++++++++++++++++++++++ spec/services/gpx/track_parser_spec.rb | 10 ++++++ 4 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 spec/fixtures/files/gpx/arc_example.gpx diff --git a/CHANGELOG.md b/CHANGELOG.md index 81a8b8e6..d6609218 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - A test for building rc Docker image. +### Fixed + +- Fix authentication to `GET /api/v1/countries/visited_cities` with header `Authorization: Bearer YOUR_API_KEY` instead of `api_key` query param. #679 +- Fix a bug where a gpx file with empty tracks was not being imported. #646 + # 0.23.3 - 2025-01-21 ### Changed diff --git a/app/services/gpx/track_parser.rb b/app/services/gpx/track_parser.rb index 65cbc3be..10f13983 100644 --- a/app/services/gpx/track_parser.rb +++ b/app/services/gpx/track_parser.rb @@ -15,7 +15,7 @@ class Gpx::TrackParser tracks = json['gpx']['trk'] tracks_arr = tracks.is_a?(Array) ? tracks : [tracks] - tracks_arr.map { parse_track(_1) }.flatten.each.with_index(1) do |point, index| + tracks_arr.map { parse_track(_1) }.flatten.compact.each.with_index(1) do |point, index| create_point(point, index) end end @@ -23,6 +23,8 @@ class Gpx::TrackParser private def parse_track(track) + return if track['trkseg'].blank? + segments = track['trkseg'] segments_array = segments.is_a?(Array) ? segments : [segments] diff --git a/spec/fixtures/files/gpx/arc_example.gpx b/spec/fixtures/files/gpx/arc_example.gpx new file mode 100644 index 00000000..f944f776 --- /dev/null +++ b/spec/fixtures/files/gpx/arc_example.gpx @@ -0,0 +1,41 @@ + + + + + 89.9031832732575 + Topland Hotel & Convention Center + + + walking + + + + taxi + + + 49.96302288016834 + + + + 49.884678590538186 + + + + 49.71960135141746 + + + + 49.91594081568717 + + + + 50.344669848377556 + + + + 50.12800953488726 + + + + + diff --git a/spec/services/gpx/track_parser_spec.rb b/spec/services/gpx/track_parser_spec.rb index b1026143..c5980c91 100644 --- a/spec/services/gpx/track_parser_spec.rb +++ b/spec/services/gpx/track_parser_spec.rb @@ -74,5 +74,15 @@ RSpec.describe Gpx::TrackParser do expect(Point.first.velocity).to eq('2.8') end end + + context 'when file exported from Arc' do + context 'when file has empty tracks' do + let(:file_path) { Rails.root.join('spec/fixtures/files/gpx/arc_example.gpx') } + + it 'creates points' do + expect { parser }.to change { Point.count }.by(6) + end + end + end end end