From 421a20ba8c5e6d1901b6d58becc939ff6f4dc456 Mon Sep 17 00:00:00 2001 From: tetebueno <9064236+tetebueno@users.noreply.github.com> Date: Mon, 16 Jun 2025 12:58:39 -0300 Subject: [PATCH 1/3] Using Redis default directory for data. For some reason for original Docker compose configuration path `/data` was correct, but for production this directory is used which isn't used by Redis, except if it's configured expressly. Checked here: https://github.com/redis/docker-library-redis/blob/master/7.4/alpine/Dockerfile#L134 --- docker/docker-compose.production.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/docker-compose.production.yml b/docker/docker-compose.production.yml index 5705da9b..608a916e 100644 --- a/docker/docker-compose.production.yml +++ b/docker/docker-compose.production.yml @@ -8,7 +8,7 @@ services: networks: - dawarich volumes: - - dawarich_redis_data:/var/shared/redis + - dawarich_redis_data:/data restart: always healthcheck: test: [ "CMD", "redis-cli", "--raw", "incr", "ping" ] From 6b96e1f0bec4e841df249a064a8fe225271e77d7 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Sat, 12 Jul 2025 17:21:53 +0200 Subject: [PATCH 2/3] Revert specs --- app/jobs/area_visits_calculating_job.rb | 2 +- .../area_visits_calculation_scheduling_job.rb | 2 +- ...a_visits_calculation_scheduling_job_spec.rb | 16 ++++------------ ...art_settings_points_country_ids_job_spec.rb | 9 +-------- spec/rails_helper.rb | 10 +++++++++- .../points/fetch_data_spec.rb | 16 +--------------- spec/services/users/export_data/points_spec.rb | 9 +-------- spec/services/visits/suggest_spec.rb | 18 ------------------ 8 files changed, 18 insertions(+), 64 deletions(-) diff --git a/app/jobs/area_visits_calculating_job.rb b/app/jobs/area_visits_calculating_job.rb index 95850286..31c6635a 100644 --- a/app/jobs/area_visits_calculating_job.rb +++ b/app/jobs/area_visits_calculating_job.rb @@ -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) diff --git a/app/jobs/area_visits_calculation_scheduling_job.rb b/app/jobs/area_visits_calculation_scheduling_job.rb index db4c5d3e..5725cb1c 100644 --- a/app/jobs/area_visits_calculation_scheduling_job.rb +++ b/app/jobs/area_visits_calculation_scheduling_job.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class AreaVisitsCalculationSchedulingJob < ApplicationJob - queue_as :default + queue_as :visit_suggesting sidekiq_options retry: false def perform diff --git a/spec/jobs/area_visits_calculation_scheduling_job_spec.rb b/spec/jobs/area_visits_calculation_scheduling_job_spec.rb index edba8127..c2e1bbeb 100644 --- a/spec/jobs/area_visits_calculation_scheduling_job_spec.rb +++ b/spec/jobs/area_visits_calculation_scheduling_job_spec.rb @@ -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 diff --git a/spec/jobs/data_migrations/start_settings_points_country_ids_job_spec.rb b/spec/jobs/data_migrations/start_settings_points_country_ids_job_spec.rb index 8b6dc072..7570704a 100644 --- a/spec/jobs/data_migrations/start_settings_points_country_ids_job_spec.rb +++ b/spec/jobs/data_migrations/start_settings_points_country_ids_job_spec.rb @@ -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) diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 99844b0a..7275e402 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -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| diff --git a/spec/services/reverse_geocoding/points/fetch_data_spec.rb b/spec/services/reverse_geocoding/points/fetch_data_spec.rb index a0b4a7fa..b9ed2a75 100644 --- a/spec/services/reverse_geocoding/points/fetch_data_spec.rb +++ b/spec/services/reverse_geocoding/points/fetch_data_spec.rb @@ -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' } diff --git a/spec/services/users/export_data/points_spec.rb b/spec/services/users/export_data/points_spec.rb index b5f40c2a..b2fa0a52 100644 --- a/spec/services/users/export_data/points_spec.rb +++ b/spec/services/users/export_data/points_spec.rb @@ -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 diff --git a/spec/services/visits/suggest_spec.rb b/spec/services/visits/suggest_spec.rb index f5a49e61..167b9ba9 100644 --- a/spec/services/visits/suggest_spec.rb +++ b/spec/services/visits/suggest_spec.rb @@ -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) From 43bc8c444c881678b679c1907448fadfe9947ce9 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Sat, 12 Jul 2025 17:57:22 +0200 Subject: [PATCH 3/3] Fix name fetcher --- app/services/places/name_fetcher.rb | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/app/services/places/name_fetcher.rb b/app/services/places/name_fetcher.rb index 1bdf5821..3a817dda 100644 --- a/app/services/places/name_fetcher.rb +++ b/app/services/places/name_fetcher.rb @@ -15,16 +15,18 @@ module Places return if properties.blank? ActiveRecord::Base.transaction do - @place.name = properties['name'] - @place.city = properties['city'] - @place.country = properties['country'] + @place.name = properties['name'] if properties['name'].present? + @place.city = properties['city'] if properties['city'].present? + @place.country = properties['country'] if properties['country'].present? @place.geodata = geodata.data if DawarichSettings.store_geodata? @place.save! - @place - .visits - .where(name: Place::DEFAULT_NAME) - .update_all(name: properties['name']) + if properties['name'].present? + @place + .visits + .where(name: Place::DEFAULT_NAME) + .update_all(name: properties['name']) + end @place end