dawarich/spec/services/users/import_data/places_streaming_spec.rb
Evgenii Burmakin b1393ee674
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 19:45:09 +01:00

53 lines
1.7 KiB
Ruby

# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Users::ImportData::Places do
let(:user) { create(:user) }
let(:logger) { instance_double(Logger, info: nil, debug: nil, error: nil) }
let(:service) { described_class.new(user, nil, logger: logger) }
describe '#add / #finalize' do
it 'creates places in batches and tracks total created' do
2.times do |index|
service.add(
'name' => "Place #{index}",
'latitude' => 10.0 + index,
'longitude' => 20.0 + index
)
end
expect { service.finalize }.to change(Place, :count).by(2)
expect { expect(service.finalize).to eq(2) }.not_to change(Place, :count)
end
it 'flushes automatically when the buffer reaches the batch size' do
stub_const('Users::ImportData::Places::BATCH_SIZE', 2)
logger_double = instance_double(Logger)
allow(logger_double).to receive(:info)
allow(logger_double).to receive(:debug)
allow(logger_double).to receive(:error)
buffered_service = described_class.new(user, nil, batch_size: 2, logger: logger_double)
buffered_service.add('name' => 'First', 'latitude' => 1, 'longitude' => 2)
expect(Place.global.count).to eq(0)
buffered_service.add('name' => 'Second', 'latitude' => 3, 'longitude' => 4)
expect(Place.global.count).to eq(2)
expect(buffered_service.finalize).to eq(2)
expect { buffered_service.finalize }.not_to change(Place, :count)
end
it 'skips invalid records and logs debug messages' do
allow(logger).to receive(:debug)
service.add('name' => 'Valid', 'latitude' => 1, 'longitude' => 2)
service.add('name' => 'Missing coords')
expect(service.finalize).to eq(1)
end
end
end