mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-10 01:01:39 -05:00
Revert specs
This commit is contained in:
parent
0dff80e12b
commit
6b96e1f0be
8 changed files with 18 additions and 64 deletions
|
|
@ -1,7 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AreaVisitsCalculatingJob < ApplicationJob
|
||||
queue_as :default
|
||||
queue_as :visit_suggesting
|
||||
sidekiq_options retry: false
|
||||
|
||||
def perform(user_id)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AreaVisitsCalculationSchedulingJob < ApplicationJob
|
||||
queue_as :default
|
||||
queue_as :visit_suggesting
|
||||
sidekiq_options retry: false
|
||||
|
||||
def perform
|
||||
|
|
|
|||
|
|
@ -4,21 +4,13 @@ require 'rails_helper'
|
|||
|
||||
RSpec.describe AreaVisitsCalculationSchedulingJob, type: :job do
|
||||
describe '#perform' do
|
||||
let(:user1) { create(:user) }
|
||||
let(:user2) { create(:user) }
|
||||
let!(:user) { create(:user) }
|
||||
let!(:area) { create(:area, user: user) }
|
||||
|
||||
it 'calls the AreaVisitsCalculationService' do
|
||||
# Create users first
|
||||
user1
|
||||
user2
|
||||
expect(AreaVisitsCalculatingJob).to receive(:perform_later).with(user.id)
|
||||
|
||||
# Mock User.find_each to only return our test users
|
||||
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
|
||||
described_class.new.perform_now
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -9,11 +9,6 @@ RSpec.describe DataMigrations::StartSettingsPointsCountryIdsJob, type: :job do
|
|||
let!(:point_without_country2) { create(:point, country_id: nil) }
|
||||
|
||||
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 \
|
||||
have_enqueued_job(DataMigrations::SetPointsCountryIdsJob)
|
||||
.with(point_without_country1.id)
|
||||
|
|
@ -22,9 +17,7 @@ RSpec.describe DataMigrations::StartSettingsPointsCountryIdsJob, type: :job do
|
|||
end
|
||||
|
||||
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)
|
||||
allow(Point).to receive_message_chain(:where, :find_each)
|
||||
.and_return([])
|
||||
point_with_country.update(country_id: 1)
|
||||
|
||||
expect { described_class.perform_now }.not_to \
|
||||
have_enqueued_job(DataMigrations::SetPointsCountryIdsJob)
|
||||
|
|
|
|||
|
|
@ -40,8 +40,10 @@ RSpec.configure do |config|
|
|||
config.rswag_dry_run = false
|
||||
|
||||
config.before(:suite) do
|
||||
# Ensure Rails routes are loaded for Devise
|
||||
Rails.application.reload_routes!
|
||||
|
||||
# DatabaseCleaner.strategy = :transaction
|
||||
# DatabaseCleaner.clean_with(:truncation)
|
||||
end
|
||||
|
||||
config.before do
|
||||
|
|
@ -90,6 +92,12 @@ RSpec.configure do |config|
|
|||
config.after(:suite) do
|
||||
Rake::Task['rswag:generate'].invoke
|
||||
end
|
||||
|
||||
# config.around(:each) do |example|
|
||||
# DatabaseCleaner.cleaning do
|
||||
# example.run
|
||||
# end
|
||||
# end
|
||||
end
|
||||
|
||||
Shoulda::Matchers.configure do |config|
|
||||
|
|
|
|||
|
|
@ -5,12 +5,7 @@ require 'rails_helper'
|
|||
RSpec.describe ReverseGeocoding::Points::FetchData do
|
||||
subject(:fetch_data) { described_class.new(point.id).call }
|
||||
|
||||
let(:point) do
|
||||
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
|
||||
let(:point) { create(:point) }
|
||||
|
||||
context 'when Geocoder returns city and country' do
|
||||
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
|
||||
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 }
|
||||
.from(nil).to('Berlin')
|
||||
.and change { point.reload.country_id }.from(nil).to(germany.id)
|
||||
end
|
||||
|
||||
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
|
||||
country = point.reload.country
|
||||
expect(country.name).to eq('Germany')
|
||||
|
|
@ -52,9 +41,6 @@ RSpec.describe ReverseGeocoding::Points::FetchData do
|
|||
end
|
||||
|
||||
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(
|
||||
'address' => 'Address',
|
||||
'properties' => { 'countrycode' => 'DE' }
|
||||
|
|
|
|||
|
|
@ -56,20 +56,13 @@ RSpec.describe Users::ExportData::Points, type: :service do
|
|||
)
|
||||
end
|
||||
let(:point_without_relationships) do
|
||||
point = create(:point,
|
||||
create(:point,
|
||||
user: user,
|
||||
timestamp: 1640995260,
|
||||
longitude: -73.9857,
|
||||
latitude: 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
|
||||
|
||||
before do
|
||||
|
|
|
|||
|
|
@ -87,24 +87,6 @@ RSpec.describe Visits::Suggest do
|
|||
end
|
||||
|
||||
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
|
||||
|
||||
expect(enqueued_jobs.count).to eq(2)
|
||||
|
|
|
|||
Loading…
Reference in a new issue