diff --git a/app/jobs/points/nightly_reverse_geocoding_job.rb b/app/jobs/points/nightly_reverse_geocoding_job.rb index 5321f624..d0d5de51 100644 --- a/app/jobs/points/nightly_reverse_geocoding_job.rb +++ b/app/jobs/points/nightly_reverse_geocoding_job.rb @@ -13,7 +13,6 @@ class Points::NightlyReverseGeocodingJob < ApplicationJob processed_user_ids.add(point.user_id) end - # Invalidate caches for all users who had points reverse geocoded processed_user_ids.each do |user_id| Cache::InvalidateUserCaches.new(user_id).call end diff --git a/app/services/stats/calculate_month.rb b/app/services/stats/calculate_month.rb index 7b8a5bb9..0a87b803 100644 --- a/app/services/stats/calculate_month.rb +++ b/app/services/stats/calculate_month.rb @@ -26,7 +26,7 @@ class Stats::CalculateMonth def start_timestamp = DateTime.new(year, month, 1).to_i def end_timestamp - DateTime.new(year, month, -1).to_i # -1 returns last day of month + DateTime.new(year, month, -1).to_i end def update_month_stats(year, month) @@ -43,7 +43,6 @@ class Stats::CalculateMonth stat.save! - # Invalidate user caches after stats calculation since they may have changed Cache::InvalidateUserCaches.new(user.id).call end end diff --git a/spec/jobs/imports/destroy_job_spec.rb b/spec/jobs/imports/destroy_job_spec.rb index 3a50c638..8492015e 100644 --- a/spec/jobs/imports/destroy_job_spec.rb +++ b/spec/jobs/imports/destroy_job_spec.rb @@ -15,7 +15,6 @@ RSpec.describe Imports::DestroyJob, type: :job do context 'when import exists' do before do - # Create some points for the import create_list(:point, 3, user: user, import: import) end @@ -113,7 +112,6 @@ RSpec.describe Imports::DestroyJob, type: :job do described_class.perform_now(non_existent_id) - # Early return at line 8 doesn't log, only rescue block does expect(Rails.logger).not_to have_received(:warn) end end @@ -158,7 +156,9 @@ RSpec.describe Imports::DestroyJob, type: :job do it 'has already set status to deleting before service is called' do expect do - described_class.perform_now(import.id) rescue StandardError + described_class.perform_now(import.id) + rescue StandardError + StandardError end.to change { import.reload.status }.to('deleting') end end diff --git a/spec/jobs/points/nightly_reverse_geocoding_job_spec.rb b/spec/jobs/points/nightly_reverse_geocoding_job_spec.rb index 0465852f..b600f9f3 100644 --- a/spec/jobs/points/nightly_reverse_geocoding_job_spec.rb +++ b/spec/jobs/points/nightly_reverse_geocoding_job_spec.rb @@ -7,7 +7,6 @@ RSpec.describe Points::NightlyReverseGeocodingJob, type: :job do let(:user) { create(:user) } before do - # Clear any existing jobs and points to ensure test isolation ActiveJob::Base.queue_adapter.enqueued_jobs.clear Point.delete_all end @@ -126,11 +125,14 @@ RSpec.describe Points::NightlyReverseGeocodingJob, type: :job do end it 'does not invalidate caches multiple times for the same user' do - # user has 2 points, but cache should only be invalidated once cache_service = instance_double(Cache::InvalidateUserCaches) allow(Cache::InvalidateUserCaches).to receive(:new).with(user.id).and_return(cache_service) - allow(Cache::InvalidateUserCaches).to receive(:new).with(user2.id).and_return(instance_double(Cache::InvalidateUserCaches, call: nil)) + allow(Cache::InvalidateUserCaches).to receive(:new).with(user2.id).and_return( + instance_double( + Cache::InvalidateUserCaches, call: nil + ) + ) allow(cache_service).to receive(:call) described_class.perform_now diff --git a/spec/services/cache/invalidate_user_caches_spec.rb b/spec/services/cache/invalidate_user_caches_spec.rb index 27fc5f2c..241a2d2a 100644 --- a/spec/services/cache/invalidate_user_caches_spec.rb +++ b/spec/services/cache/invalidate_user_caches_spec.rb @@ -8,20 +8,17 @@ RSpec.describe Cache::InvalidateUserCaches do describe '#call' do it 'invalidates all user-related caches' do - # Pre-populate the caches - Rails.cache.write("dawarich/user_#{user.id}_countries_visited", ['USA', 'Canada']) + Rails.cache.write("dawarich/user_#{user.id}_countries_visited", %w[USA Canada]) Rails.cache.write("dawarich/user_#{user.id}_cities_visited", ['New York', 'Toronto']) Rails.cache.write("dawarich/user_#{user.id}_points_geocoded_stats", { geocoded: 100, without_data: 10 }) - # Verify caches are populated - expect(Rails.cache.read("dawarich/user_#{user.id}_countries_visited")).to eq(['USA', 'Canada']) + expect(Rails.cache.read("dawarich/user_#{user.id}_countries_visited")).to eq(%w[USA Canada]) expect(Rails.cache.read("dawarich/user_#{user.id}_cities_visited")).to eq(['New York', 'Toronto']) - expect(Rails.cache.read("dawarich/user_#{user.id}_points_geocoded_stats")).to eq({ geocoded: 100, without_data: 10 }) + expect(Rails.cache.read("dawarich/user_#{user.id}_points_geocoded_stats")).to eq({ geocoded: 100, +without_data: 10 }) - # Invalidate caches service.call - # Verify caches are cleared expect(Rails.cache.read("dawarich/user_#{user.id}_countries_visited")).to be_nil expect(Rails.cache.read("dawarich/user_#{user.id}_cities_visited")).to be_nil expect(Rails.cache.read("dawarich/user_#{user.id}_points_geocoded_stats")).to be_nil @@ -30,7 +27,7 @@ RSpec.describe Cache::InvalidateUserCaches do describe '#invalidate_countries_visited' do it 'deletes the countries_visited cache' do - Rails.cache.write("dawarich/user_#{user.id}_countries_visited", ['USA', 'Canada']) + Rails.cache.write("dawarich/user_#{user.id}_countries_visited", %w[USA Canada]) service.invalidate_countries_visited diff --git a/spec/services/stats/calculate_month_spec.rb b/spec/services/stats/calculate_month_spec.rb index 6c4b83b1..746d0648 100644 --- a/spec/services/stats/calculate_month_spec.rb +++ b/spec/services/stats/calculate_month_spec.rb @@ -204,7 +204,6 @@ RSpec.describe Stats::CalculateMonth do context 'when invalidating caches' do it 'invalidates user caches after updating stats' do - # Use existing points from the parent context cache_service = instance_double(Cache::InvalidateUserCaches) allow(Cache::InvalidateUserCaches).to receive(:new).with(user.id).and_return(cache_service) allow(cache_service).to receive(:call)