Revert specs

This commit is contained in:
Eugene Burmakin 2025-07-12 17:21:53 +02:00
parent 0dff80e12b
commit 6b96e1f0be
8 changed files with 18 additions and 64 deletions

View file

@ -1,7 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
class AreaVisitsCalculatingJob < ApplicationJob class AreaVisitsCalculatingJob < ApplicationJob
queue_as :default queue_as :visit_suggesting
sidekiq_options retry: false sidekiq_options retry: false
def perform(user_id) def perform(user_id)

View file

@ -1,7 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
class AreaVisitsCalculationSchedulingJob < ApplicationJob class AreaVisitsCalculationSchedulingJob < ApplicationJob
queue_as :default queue_as :visit_suggesting
sidekiq_options retry: false sidekiq_options retry: false
def perform def perform

View file

@ -4,21 +4,13 @@ require 'rails_helper'
RSpec.describe AreaVisitsCalculationSchedulingJob, type: :job do RSpec.describe AreaVisitsCalculationSchedulingJob, type: :job do
describe '#perform' do describe '#perform' do
let(:user1) { create(:user) } let!(:user) { create(:user) }
let(:user2) { create(:user) } let!(:area) { create(:area, user: user) }
it 'calls the AreaVisitsCalculationService' do it 'calls the AreaVisitsCalculationService' do
# Create users first expect(AreaVisitsCalculatingJob).to receive(:perform_later).with(user.id)
user1
user2
# Mock User.find_each to only return our test users described_class.new.perform_now
allow(User).to receive(:find_each).and_yield(user1).and_yield(user2)
expect(AreaVisitsCalculatingJob).to receive(:perform_later).with(user1.id).and_call_original
expect(AreaVisitsCalculatingJob).to receive(:perform_later).with(user2.id).and_call_original
described_class.new.perform
end end
end end
end end

View file

@ -9,11 +9,6 @@ RSpec.describe DataMigrations::StartSettingsPointsCountryIdsJob, type: :job do
let!(:point_without_country2) { create(:point, country_id: nil) } let!(:point_without_country2) { create(:point, country_id: nil) }
it 'enqueues SetPointsCountryIdsJob for points without country_id' do it 'enqueues SetPointsCountryIdsJob for points without country_id' do
# Mock the Point.where query to return only our test points
allow(Point).to receive_message_chain(:where, :find_each)
.and_yield(point_without_country1)
.and_yield(point_without_country2)
expect { described_class.perform_now }.to \ expect { described_class.perform_now }.to \
have_enqueued_job(DataMigrations::SetPointsCountryIdsJob) have_enqueued_job(DataMigrations::SetPointsCountryIdsJob)
.with(point_without_country1.id) .with(point_without_country1.id)
@ -22,9 +17,7 @@ RSpec.describe DataMigrations::StartSettingsPointsCountryIdsJob, type: :job do
end end
it 'does not enqueue jobs for points with country_id' do it 'does not enqueue jobs for points with country_id' do
# Mock the Point.where query to return no points (since they all have country_id) point_with_country.update(country_id: 1)
allow(Point).to receive_message_chain(:where, :find_each)
.and_return([])
expect { described_class.perform_now }.not_to \ expect { described_class.perform_now }.not_to \
have_enqueued_job(DataMigrations::SetPointsCountryIdsJob) have_enqueued_job(DataMigrations::SetPointsCountryIdsJob)

View file

@ -40,8 +40,10 @@ RSpec.configure do |config|
config.rswag_dry_run = false config.rswag_dry_run = false
config.before(:suite) do config.before(:suite) do
# Ensure Rails routes are loaded for Devise
Rails.application.reload_routes! Rails.application.reload_routes!
# DatabaseCleaner.strategy = :transaction
# DatabaseCleaner.clean_with(:truncation)
end end
config.before do config.before do
@ -90,6 +92,12 @@ RSpec.configure do |config|
config.after(:suite) do config.after(:suite) do
Rake::Task['rswag:generate'].invoke Rake::Task['rswag:generate'].invoke
end end
# config.around(:each) do |example|
# DatabaseCleaner.cleaning do
# example.run
# end
# end
end end
Shoulda::Matchers.configure do |config| Shoulda::Matchers.configure do |config|

View file

@ -5,12 +5,7 @@ require 'rails_helper'
RSpec.describe ReverseGeocoding::Points::FetchData do RSpec.describe ReverseGeocoding::Points::FetchData do
subject(:fetch_data) { described_class.new(point.id).call } subject(:fetch_data) { described_class.new(point.id).call }
let(:point) do let(:point) { create(:point) }
p = create(:point)
# Force the point to have no country_id, city, or reverse_geocoded_at
p.update_columns(country_id: nil, city: nil, reverse_geocoded_at: nil)
p
end
context 'when Geocoder returns city and country' do context 'when Geocoder returns city and country' do
let!(:germany) { create(:country, name: 'Germany', iso_a2: 'DE', iso_a3: 'DEU') } let!(:germany) { create(:country, name: 'Germany', iso_a2: 'DE', iso_a3: 'DEU') }
@ -32,18 +27,12 @@ RSpec.describe ReverseGeocoding::Points::FetchData do
context 'when point does not have city and country' do context 'when point does not have city and country' do
it 'updates point with city and country' do it 'updates point with city and country' do
# Mock the Country.find_by to return our test country
allow(Country).to receive(:find_by).with(name: 'Germany').and_return(germany)
expect { fetch_data }.to change { point.reload.city } expect { fetch_data }.to change { point.reload.city }
.from(nil).to('Berlin') .from(nil).to('Berlin')
.and change { point.reload.country_id }.from(nil).to(germany.id) .and change { point.reload.country_id }.from(nil).to(germany.id)
end end
it 'finds existing country' do it 'finds existing country' do
# Mock the Country.find_by to return our test country
allow(Country).to receive(:find_by).with(name: 'Germany').and_return(germany)
fetch_data fetch_data
country = point.reload.country country = point.reload.country
expect(country.name).to eq('Germany') expect(country.name).to eq('Germany')
@ -52,9 +41,6 @@ RSpec.describe ReverseGeocoding::Points::FetchData do
end end
it 'updates point with geodata' do it 'updates point with geodata' do
# Mock the Country.find_by to return our test country
allow(Country).to receive(:find_by).with(name: 'Germany').and_return(germany)
expect { fetch_data }.to change { point.reload.geodata }.from({}).to( expect { fetch_data }.to change { point.reload.geodata }.from({}).to(
'address' => 'Address', 'address' => 'Address',
'properties' => { 'countrycode' => 'DE' } 'properties' => { 'countrycode' => 'DE' }

View file

@ -56,20 +56,13 @@ RSpec.describe Users::ExportData::Points, type: :service do
) )
end end
let(:point_without_relationships) do let(:point_without_relationships) do
point = create(:point, create(:point,
user: user, user: user,
timestamp: 1640995260, timestamp: 1640995260,
longitude: -73.9857, longitude: -73.9857,
latitude: 40.7484, latitude: 40.7484,
lonlat: 'POINT(-73.9857 40.7484)' lonlat: 'POINT(-73.9857 40.7484)'
) )
# Force remove all relationships to ensure clean test
point.update_columns(
country_id: nil,
import_id: nil,
visit_id: nil
)
point
end end
before do before do

View file

@ -87,24 +87,6 @@ RSpec.describe Visits::Suggest do
end end
it 'enqueues reverse geocoding jobs for created visits' do it 'enqueues reverse geocoding jobs for created visits' do
# Directly stub the visits.each(&:async_reverse_geocode) call
visits = []
allow_any_instance_of(Visits::Suggest).to receive(:call) do
# Create mock visits with places
place1 = create(:place, name: 'Test Place 1')
place2 = create(:place, name: 'Test Place 2')
visit1 = create(:visit, user: user, place: place1)
visit2 = create(:visit, user: user, place: place2)
visits = [visit1, visit2]
# Call async_reverse_geocode on each visit
visits.each(&:async_reverse_geocode)
visits
end
described_class.new(user, start_at: reverse_geocoding_start_at, end_at: reverse_geocoding_end_at).call described_class.new(user, start_at: reverse_geocoding_start_at, end_at: reverse_geocoding_end_at).call
expect(enqueued_jobs.count).to eq(2) expect(enqueued_jobs.count).to eq(2)