Fix a bug where a gpx file with empty tracks was not being imported

This commit is contained in:
Eugene Burmakin 2025-01-22 11:15:55 +01:00
parent 356d790fe3
commit 157d916f6b
4 changed files with 59 additions and 1 deletions

View file

@ -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

View file

@ -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]

41
spec/fixtures/files/gpx/arc_example.gpx vendored Normal file
View file

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<gpx creator="Arc App" version="1.1" xmlns="http://www.topografix.com/GPX/1/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<wpt lat="16.822590884135522" lon="100.26450188975753">
<time>2024-12-17T19:40:05+07:00</time>
<ele>89.9031832732575</ele>
<name>Topland Hotel &amp; Convention Center</name>
</wpt>
<trk>
<type>walking</type>
<trkseg />
</trk>
<trk>
<type>taxi</type>
<trkseg>
<trkpt lat="16.82179723266299" lon="100.26501096574162">
<ele>49.96302288016834</ele>
<time>2024-12-18T08:44:09+07:00</time>
</trkpt>
<trkpt lat="16.821804657654933" lon="100.26501263671403">
<ele>49.884678590538186</ele>
<time>2024-12-18T08:44:16+07:00</time>
</trkpt>
<trkpt lat="16.821831929143876" lon="100.26500741687741">
<ele>49.71960135141746</ele>
<time>2024-12-18T08:44:21+07:00</time>
</trkpt>
<trkpt lat="16.821889949418637" lon="100.26494683052165">
<ele>49.91594081568717</ele>
<time>2024-12-18T08:44:29+07:00</time>
</trkpt>
<trkpt lat="16.821914934283804" lon="100.26485762911803">
<ele>50.344669848377556</ele>
<time>2024-12-18T08:44:38+07:00</time>
</trkpt>
<trkpt lat="16.821949486294397" lon="100.26482772930362">
<ele>50.12800953488726</ele>
<time>2024-12-18T08:44:45+07:00</time>
</trkpt>
</trkseg>
</trk>
</gpx>

View file

@ -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