dawarich/spec/jobs/data_migrations/migrate_places_lonlat_job_spec.rb

81 lines
2.5 KiB
Ruby
Raw Permalink Normal View History

2025-03-09 11:29:16 -04:00
# frozen_string_literal: true
2025-03-03 14:50:49 -05:00
require 'rails_helper'
RSpec.describe DataMigrations::MigratePlacesLonlatJob, type: :job do
2025-03-09 11:29:16 -04:00
describe '#perform' do
let(:user) { create(:user) }
context 'when places exist for the user' do
0.36.0 (#1952) * Implement OmniAuth GitHub authentication * Fix omniauth GitHub scope to include user email access * Remove margin-bottom * Implement Google OAuth2 authentication * Implement OIDC authentication for Dawarich using omniauth_openid_connect gem. * Add patreon account linking and patron checking service * Update docker-compose.yml to use boolean values instead of strings * Add support for KML files * Add tests * Update changelog * Remove patreon OAuth integration * Move omniauthable to a concern * Update an icon in integrations * Update changelog * Update app version * Fix family location sharing toggle * Move family location sharing to its own controller * Update changelog * Implement basic tagging functionality for places, allowing users to categorize and label places with custom tags. * Add places management API and tags feature * Add some changes related to places management feature * Fix some tests * Fix sometests * Add places layer * Update places layer to use Leaflet.Control.Layers.Tree for hierarchical layer control * Rework tag form * Add hashtag * Add privacy zones to tags * Add notes to places and manage place tags * Update changelog * Update e2e tests * Extract tag serializer to its own file * Fix some tests * Fix tags request specs * Fix some tests * Fix rest of the tests * Revert some changes * Add missing specs * Revert changes in place export/import code * Fix some specs * Fix PlaceFinder to only consider global places when finding existing places * Fix few more specs * Fix visits creator spec * Fix last tests * Update place creating modal * Add home location based on "Home" tagged place * Save enabled tag layers * Some fixes * Fix bug where enabling place tag layers would trigger saving enabled layers, overwriting with incomplete data * Update migration to use disable_ddl_transaction! and add up/down methods * Fix tag layers restoration and filtering logic * Update OIDC auto-registration and email/password registration settings * Fix potential xss
2025-11-24 13:45:09 -05:00
let!(:place1) { create(:place, user: user, longitude: 10.0, latitude: 20.0) }
let!(:place2) { create(:place, user: user, longitude: -73.935242, latitude: 40.730610) }
let!(:other_place) { create(:place, longitude: 15.0, latitude: 25.0) }
2025-03-09 11:29:16 -04:00
# Create visits to associate places with users
let!(:visit1) { create(:visit, user: user, place: place1) }
let!(:visit2) { create(:visit, user: user, place: place2) }
let!(:other_visit) { create(:visit, place: other_place) } # associated with a different user
0.36.0 (#1952) * Implement OmniAuth GitHub authentication * Fix omniauth GitHub scope to include user email access * Remove margin-bottom * Implement Google OAuth2 authentication * Implement OIDC authentication for Dawarich using omniauth_openid_connect gem. * Add patreon account linking and patron checking service * Update docker-compose.yml to use boolean values instead of strings * Add support for KML files * Add tests * Update changelog * Remove patreon OAuth integration * Move omniauthable to a concern * Update an icon in integrations * Update changelog * Update app version * Fix family location sharing toggle * Move family location sharing to its own controller * Update changelog * Implement basic tagging functionality for places, allowing users to categorize and label places with custom tags. * Add places management API and tags feature * Add some changes related to places management feature * Fix some tests * Fix sometests * Add places layer * Update places layer to use Leaflet.Control.Layers.Tree for hierarchical layer control * Rework tag form * Add hashtag * Add privacy zones to tags * Add notes to places and manage place tags * Update changelog * Update e2e tests * Extract tag serializer to its own file * Fix some tests * Fix tags request specs * Fix some tests * Fix rest of the tests * Revert some changes * Add missing specs * Revert changes in place export/import code * Fix some specs * Fix PlaceFinder to only consider global places when finding existing places * Fix few more specs * Fix visits creator spec * Fix last tests * Update place creating modal * Add home location based on "Home" tagged place * Save enabled tag layers * Some fixes * Fix bug where enabling place tag layers would trigger saving enabled layers, overwriting with incomplete data * Update migration to use disable_ddl_transaction! and add up/down methods * Fix tag layers restoration and filtering logic * Update OIDC auto-registration and email/password registration settings * Fix potential xss
2025-11-24 13:45:09 -05:00
# Simulate old data by clearing lonlat after creation (to test migration)
before do
place1.update_column(:lonlat, nil)
place2.update_column(:lonlat, nil)
other_place.update_column(:lonlat, nil)
end
2025-03-09 11:29:16 -04:00
it 'updates lonlat field for all places belonging to the user' do
# Force a reload to ensure we have the initial state
place1.reload
place2.reload
# Both places should have nil lonlat initially
expect(place1.lonlat).to be_nil
expect(place2.lonlat).to be_nil
# Run the job
described_class.perform_now(user.id)
# Reload to get updated state
place1.reload
place2.reload
other_place.reload
# Check that lonlat is now set correctly
expect(place1.lonlat).not_to be_nil
expect(place2.lonlat).not_to be_nil
# The other user's place should still have nil lonlat
expect(other_place.lonlat).to be_nil
# Verify the coordinates
expect(place1.lonlat.x).to eq(10.0) # longitude
expect(place1.lonlat.y).to eq(20.0) # latitude
expect(place2.lonlat.x).to eq(-73.935242) # longitude
expect(place2.lonlat.y).to eq(40.730610) # latitude
end
it 'sets the correct SRID (4326) on the geometry' do
described_class.perform_now(user.id)
place1.reload
expect(place1.lonlat.srid).to eq(4326)
end
end
context 'when no places exist for the user' do
it 'completes successfully without errors' do
expect do
described_class.perform_now(user.id)
end.not_to raise_error
end
end
end
describe 'queue' do
2025-07-26 19:08:29 -04:00
it 'uses the data_migrations queue' do
expect(described_class.queue_name).to eq('data_migrations')
2025-03-09 11:29:16 -04:00
end
end
2025-03-03 14:50:49 -05:00
end