mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-10 17:21:38 -05:00
Fix specs
This commit is contained in:
parent
88e3f53cc5
commit
7ea149bd4e
4 changed files with 22 additions and 14 deletions
|
|
@ -10,6 +10,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|||
|
||||
- Track generation is now significantly faster and less resource intensive.
|
||||
|
||||
## Fixed
|
||||
|
||||
- Distance on the stats page is now rounded. #1548
|
||||
|
||||
|
||||
# [0.30.2] - 2025-07-22
|
||||
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ class Tracks::Generator
|
|||
tracks_created = 0
|
||||
|
||||
segments.each do |segment_data|
|
||||
track = create_track_from_segment_optimized(segment_data)
|
||||
track = create_track_from_segment(segment_data)
|
||||
tracks_created += 1 if track
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@
|
|||
</h2>
|
||||
<p>
|
||||
<% cache [current_user, 'year_distance_stat', year], skip_digest: true do %>
|
||||
<%= number_with_delimiter year_distance_stat(year, current_user) %><%= current_user.safe_settings.distance_unit %>
|
||||
<%= number_with_delimiter year_distance_stat(year, current_user).round %> <%= current_user.safe_settings.distance_unit %>
|
||||
<% end %>
|
||||
</p>
|
||||
<% if DawarichSettings.reverse_geocoding_enabled? %>
|
||||
|
|
|
|||
|
|
@ -39,21 +39,23 @@ RSpec.describe Tracks::TrackBuilder do
|
|||
]
|
||||
end
|
||||
|
||||
let(:pre_calculated_distance) { 1500 } # 1500 meters
|
||||
|
||||
it 'creates a track with correct attributes' do
|
||||
track = builder.create_track_from_points(points)
|
||||
track = builder.create_track_from_points(points, pre_calculated_distance)
|
||||
|
||||
expect(track).to be_persisted
|
||||
expect(track.user).to eq(user)
|
||||
expect(track.start_at).to be_within(1.second).of(Time.zone.at(points.first.timestamp))
|
||||
expect(track.end_at).to be_within(1.second).of(Time.zone.at(points.last.timestamp))
|
||||
expect(track.distance).to be > 0
|
||||
expect(track.distance).to eq(1500)
|
||||
expect(track.duration).to eq(90.minutes.to_i)
|
||||
expect(track.avg_speed).to be > 0
|
||||
expect(track.original_path).to be_present
|
||||
end
|
||||
|
||||
it 'calculates elevation statistics correctly' do
|
||||
track = builder.create_track_from_points(points)
|
||||
track = builder.create_track_from_points(points, pre_calculated_distance)
|
||||
|
||||
expect(track.elevation_gain).to eq(10) # 110 - 100
|
||||
expect(track.elevation_loss).to eq(5) # 110 - 105
|
||||
|
|
@ -62,7 +64,7 @@ RSpec.describe Tracks::TrackBuilder do
|
|||
end
|
||||
|
||||
it 'associates points with the track' do
|
||||
track = builder.create_track_from_points(points)
|
||||
track = builder.create_track_from_points(points, pre_calculated_distance)
|
||||
|
||||
points.each(&:reload)
|
||||
expect(points.map(&:track)).to all(eq(track))
|
||||
|
|
@ -73,12 +75,12 @@ RSpec.describe Tracks::TrackBuilder do
|
|||
let(:single_point) { [create(:point, user: user)] }
|
||||
|
||||
it 'returns nil for single point' do
|
||||
result = builder.create_track_from_points(single_point)
|
||||
result = builder.create_track_from_points(single_point, 1000)
|
||||
expect(result).to be_nil
|
||||
end
|
||||
|
||||
it 'returns nil for empty array' do
|
||||
result = builder.create_track_from_points([])
|
||||
result = builder.create_track_from_points([], 1000)
|
||||
expect(result).to be_nil
|
||||
end
|
||||
end
|
||||
|
|
@ -100,7 +102,7 @@ RSpec.describe Tracks::TrackBuilder do
|
|||
/Failed to create track for user #{user.id}/
|
||||
)
|
||||
|
||||
result = builder.create_track_from_points(points)
|
||||
result = builder.create_track_from_points(points, 1000)
|
||||
expect(result).to be_nil
|
||||
end
|
||||
end
|
||||
|
|
@ -120,7 +122,7 @@ RSpec.describe Tracks::TrackBuilder do
|
|||
).and_call_original
|
||||
|
||||
result = builder.build_path(points)
|
||||
expect(result).to respond_to(:as_text)
|
||||
expect(result).to be_a(RGeo::Geographic::SphericalLineStringImpl)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -134,7 +136,7 @@ RSpec.describe Tracks::TrackBuilder do
|
|||
|
||||
before do
|
||||
# Mock Point.total_distance to return distance in meters
|
||||
allow(Point).to receive(:total_distance).and_return(1500) # 1500 meters
|
||||
allow(Point).to receive(:total_distance).with(points, :m).and_return(1500) # 1500 meters
|
||||
end
|
||||
|
||||
it 'stores distance in meters regardless of user unit preference' do
|
||||
|
|
@ -143,7 +145,7 @@ RSpec.describe Tracks::TrackBuilder do
|
|||
end
|
||||
|
||||
it 'rounds distance to nearest meter' do
|
||||
allow(Point).to receive(:total_distance).and_return(1500.7)
|
||||
allow(Point).to receive(:total_distance).with(points, :m).and_return(1500.7)
|
||||
result = builder.calculate_track_distance(points)
|
||||
expect(result).to eq(1501) # Rounded to nearest meter
|
||||
end
|
||||
|
|
@ -312,13 +314,15 @@ RSpec.describe Tracks::TrackBuilder do
|
|||
]
|
||||
end
|
||||
|
||||
let(:pre_calculated_distance) { 2000 }
|
||||
|
||||
it 'creates a complete track end-to-end' do
|
||||
expect { builder.create_track_from_points(points) }.to change(Track, :count).by(1)
|
||||
expect { builder.create_track_from_points(points, pre_calculated_distance) }.to change(Track, :count).by(1)
|
||||
|
||||
track = Track.last
|
||||
expect(track.user).to eq(user)
|
||||
expect(track.points).to match_array(points)
|
||||
expect(track.distance).to be > 0
|
||||
expect(track.distance).to eq(2000)
|
||||
expect(track.duration).to eq(1.hour.to_i)
|
||||
expect(track.elevation_gain).to eq(20)
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue