mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 09:41:40 -05:00
Remove redundant spec
This commit is contained in:
parent
0cce4929f0
commit
440b031a0c
2 changed files with 7 additions and 46 deletions
|
|
@ -26,12 +26,6 @@ RSpec.describe BulkVisitsSuggestingJob, type: :job do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'schedules jobs only for active users with tracked points' do
|
it 'schedules jobs only for active users with tracked points' do
|
||||||
active_users_mock = double('ActiveRecord::Relation')
|
|
||||||
allow(User).to receive(:active).and_return(active_users_mock)
|
|
||||||
allow(active_users_mock).to receive(:active).and_return(active_users_mock)
|
|
||||||
allow(active_users_mock).to receive(:where).with(id: []).and_return(active_users_mock)
|
|
||||||
allow(active_users_mock).to receive(:find_each).and_yield(user_with_points).and_yield(user)
|
|
||||||
|
|
||||||
expect(VisitSuggestingJob).to receive(:perform_later).with(
|
expect(VisitSuggestingJob).to receive(:perform_later).with(
|
||||||
user_id: user_with_points.id,
|
user_id: user_with_points.id,
|
||||||
start_at: time_chunks.first.first,
|
start_at: time_chunks.first.first,
|
||||||
|
|
@ -64,7 +58,7 @@ RSpec.describe BulkVisitsSuggestingJob, type: :job do
|
||||||
allow(User).to receive(:active).and_return(active_users_mock)
|
allow(User).to receive(:active).and_return(active_users_mock)
|
||||||
allow(active_users_mock).to receive(:active).and_return(active_users_mock)
|
allow(active_users_mock).to receive(:active).and_return(active_users_mock)
|
||||||
allow(active_users_mock).to receive(:where).with(id: []).and_return(active_users_mock)
|
allow(active_users_mock).to receive(:where).with(id: []).and_return(active_users_mock)
|
||||||
allow(active_users_mock).to receive(:find_each).and_yield(user_with_points)
|
# allow(active_users_mock).to receive(:find_each).and_yield(user_with_points)
|
||||||
|
|
||||||
chunks.each do |chunk|
|
chunks.each do |chunk|
|
||||||
expect(VisitSuggestingJob).to receive(:perform_later).with(
|
expect(VisitSuggestingJob).to receive(:perform_later).with(
|
||||||
|
|
@ -106,11 +100,11 @@ RSpec.describe BulkVisitsSuggestingJob, type: :job do
|
||||||
.and_return(time_chunks_instance)
|
.and_return(time_chunks_instance)
|
||||||
allow(time_chunks_instance).to receive(:call).and_return(custom_chunks)
|
allow(time_chunks_instance).to receive(:call).and_return(custom_chunks)
|
||||||
|
|
||||||
active_users_mock = double('ActiveRecord::Relation')
|
# active_users_mock = double('ActiveRecord::Relation')
|
||||||
allow(User).to receive(:active).and_return(active_users_mock)
|
# allow(User).to receive(:active).and_return(active_users_mock)
|
||||||
allow(active_users_mock).to receive(:active).and_return(active_users_mock)
|
# allow(active_users_mock).to receive(:active).and_return(active_users_mock)
|
||||||
allow(active_users_mock).to receive(:where).with(id: []).and_return(active_users_mock)
|
# allow(active_users_mock).to receive(:where).with(id: []).and_return(active_users_mock)
|
||||||
allow(active_users_mock).to receive(:find_each).and_yield(user_with_points)
|
# allow(active_users_mock).to receive(:find_each).and_yield(user_with_points)
|
||||||
|
|
||||||
expect(VisitSuggestingJob).to receive(:perform_later).with(
|
expect(VisitSuggestingJob).to receive(:perform_later).with(
|
||||||
user_id: user_with_points.id,
|
user_id: user_with_points.id,
|
||||||
|
|
|
||||||
|
|
@ -94,39 +94,6 @@ RSpec.describe Points::NightlyReverseGeocodingJob, type: :job do
|
||||||
expect(relation_mock).to have_received(:find_each).with(batch_size: 1000)
|
expect(relation_mock).to have_received(:find_each).with(batch_size: 1000)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with large number of points needing reverse geocoding' do
|
|
||||||
before do
|
|
||||||
# Create 2500 points to test batching
|
|
||||||
points_data = (1..2500).map do |i|
|
|
||||||
{
|
|
||||||
user_id: user.id,
|
|
||||||
latitude: 40.7128 + (i * 0.0001),
|
|
||||||
longitude: -74.0060 + (i * 0.0001),
|
|
||||||
timestamp: Time.current.to_i + i,
|
|
||||||
lonlat: "POINT(#{-74.0060 + (i * 0.0001)} #{40.7128 + (i * 0.0001)})",
|
|
||||||
reverse_geocoded_at: nil,
|
|
||||||
created_at: Time.current,
|
|
||||||
updated_at: Time.current
|
|
||||||
}
|
|
||||||
end
|
|
||||||
Point.insert_all(points_data)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'processes all points in batches' do
|
|
||||||
expect { described_class.perform_now }.to have_enqueued_job(ReverseGeocodingJob).exactly(2500).times
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'uses efficient batching to avoid memory issues' do
|
|
||||||
relation_mock = double('ActiveRecord::Relation')
|
|
||||||
allow(Point).to receive(:not_reverse_geocoded).and_return(relation_mock)
|
|
||||||
allow(relation_mock).to receive(:find_each).with(batch_size: 1000)
|
|
||||||
|
|
||||||
described_class.perform_now
|
|
||||||
|
|
||||||
expect(relation_mock).to have_received(:find_each).with(batch_size: 1000)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'queue configuration' do
|
describe 'queue configuration' do
|
||||||
|
|
@ -155,4 +122,4 @@ RSpec.describe Points::NightlyReverseGeocodingJob, type: :job do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue