From 4a6c5bf97c16cf46352a9f81f4ee00dc21a321b5 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Wed, 12 Mar 2025 20:26:53 +0100 Subject: [PATCH 1/3] Create sample import after user is created --- app/models/user.rb | 19 + lib/assets/sample_points.gpx | 2589 ++++++++++++++++++++++++++++++++++ spec/models/user_spec.rb | 22 + 3 files changed, 2630 insertions(+) create mode 100644 lib/assets/sample_points.gpx diff --git a/app/models/user.rb b/app/models/user.rb index 2f6499d2..ee4d84f8 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -16,6 +16,7 @@ class User < ApplicationRecord has_many :trips, dependent: :destroy after_create :create_api_key + after_create :import_sample_points after_commit :activate, on: :create, if: -> { DawarichSettings.self_hosted? } before_save :sanitize_input @@ -116,4 +117,22 @@ class User < ApplicationRecord settings['photoprism_url']&.gsub!(%r{/+\z}, '') settings.try(:[], 'maps')&.try(:[], 'url')&.strip! end + + def import_sample_points + return unless Rails.env.development? || + Rails.env.production? || + (Rails.env.test? && ENV['IMPORT_SAMPLE_POINTS']) + + raw_data = Hash.from_xml( + File.read(Rails.root.join('lib/assets/sample_points.gpx')) + ) + + import = imports.create( + name: 'DELETE_ME_this_is_a_demo_import_DELETE_ME', + source: 'gpx', + raw_data: + ) + + ImportJob.perform_later(id, import.id) + end end diff --git a/lib/assets/sample_points.gpx b/lib/assets/sample_points.gpx new file mode 100644 index 00000000..df76fae0 --- /dev/null +++ b/lib/assets/sample_points.gpx @@ -0,0 +1,2589 @@ + + + + dawarich_export_from_2024-10-12_to_2024-10-12.gpx + + + + + + + + + 222.0 + + + + 225.0 + + + + 222.0 + + + + 222.0 + + + + 218.0 + + + + 217.0 + + + + 218.0 + + + + 217.0 + + + + 216.0 + + + + 214.0 + + + + 213.0 + + + + 212.0 + + + + 212.0 + + + + 212.0 + + + + 210.0 + + + + 210.0 + + + + 210.0 + + + + 209.0 + + + + 211.0 + + + + 211.0 + + + + 211.0 + + + + 211.0 + + + + 210.0 + + + + 210.0 + + + + 210.0 + + + + 210.0 + + + + 209.0 + + + + 209.0 + + + + 209.0 + + + + 211.0 + + + + 0.0 + + + + 211.0 + + + + 212.0 + + + + 212.0 + + + + 212.0 + + + + 213.0 + + + + 214.0 + + + + 214.0 + + + + 214.0 + + + + 214.0 + + + + 215.0 + + + + 215.0 + + + + 216.0 + + + + 217.0 + + + + 218.0 + + + + 219.0 + + + + 219.0 + + + + 220.0 + + + + 221.0 + + + + 221.0 + + + + 0.0 + + + + 221.0 + + + + 221.0 + + + + 221.0 + + + + 221.0 + + + + 220.0 + + + + 222.0 + + + + 222.0 + + + + 222.0 + + + + 223.0 + + + + 222.0 + + + + 223.0 + + + + 223.0 + + + + 221.0 + + + + 221.0 + + + + 223.0 + + + + 222.0 + + + + 222.0 + + + + 220.0 + + + + 219.0 + + + + 219.0 + + + + 219.0 + + + + 218.0 + + + + 219.0 + + + + 217.0 + + + + 215.0 + + + + 214.0 + + + + 212.0 + + + + 212.0 + + + + 212.0 + + + + 212.0 + + + + 212.0 + + + + 211.0 + + + + 211.0 + + + + 210.0 + + + + 210.0 + + + + 211.0 + + + + 209.0 + + + + 208.0 + + + + 206.0 + + + + 204.0 + + + + 205.0 + + + + 205.0 + + + + 204.0 + + + + 202.0 + + + + 201.0 + + + + 200.0 + + + + 199.0 + + + + 198.0 + + + + 197.0 + + + + 196.0 + + + + 197.0 + + + + 195.0 + + + + 195.0 + + + + 195.0 + + + + 196.0 + + + + 196.0 + + + + 195.0 + + + + 196.0 + + + + 195.0 + + + + 194.0 + + + + 196.0 + + + + 195.0 + + + + 193.0 + + + + 193.0 + + + + 193.0 + + + + 191.0 + + + + 191.0 + + + + 191.0 + + + + 192.0 + + + + 192.0 + + + + 193.0 + + + + 192.0 + + + + 194.0 + + + + 195.0 + + + + 198.0 + + + + 200.0 + + + + 201.0 + + + + 204.0 + + + + 205.0 + + + + 208.0 + + + + 208.0 + + + + 210.0 + + + + 210.0 + + + + 212.0 + + + + 213.0 + + + + 214.0 + + + + 217.0 + + + + 215.0 + + + + 213.0 + + + + 214.0 + + + + 214.0 + + + + 214.0 + + + + 214.0 + + + + 214.0 + + + + 214.0 + + + + 214.0 + + + + 214.0 + + + + 213.0 + + + + 212.0 + + + + 213.0 + + + + 212.0 + + + + 210.0 + + + + 210.0 + + + + 210.0 + + + + 210.0 + + + + 209.0 + + + + 209.0 + + + + 213.0 + + + + 213.0 + + + + 212.0 + + + + 210.0 + + + + 209.0 + + + + 209.0 + + + + 209.0 + + + + 209.0 + + + + 209.0 + + + + 209.0 + + + + 209.0 + + + + 209.0 + + + + 209.0 + + + + 209.0 + + + + 210.0 + + + + 211.0 + + + + 211.0 + + + + 209.0 + + + + 210.0 + + + + 208.0 + + + + 208.0 + + + + 207.0 + + + + 208.0 + + + + 207.0 + + + + 207.0 + + + + 208.0 + + + + 205.0 + + + + 204.0 + + + + 203.0 + + + + 202.0 + + + + 202.0 + + + + 202.0 + + + + 201.0 + + + + 201.0 + + + + 201.0 + + + + 203.0 + + + + 204.0 + + + + 205.0 + + + + 206.0 + + + + 206.0 + + + + 206.0 + + + + 207.0 + + + + 206.0 + + + + 207.0 + + + + 208.0 + + + + 208.0 + + + + 210.0 + + + + 211.0 + + + + 209.0 + + + + 208.0 + + + + 208.0 + + + + 207.0 + + + + 206.0 + + + + 206.0 + + + + 204.0 + + + + 204.0 + + + + 203.0 + + + + 203.0 + + + + 202.0 + + + + 203.0 + + + + 203.0 + + + + 202.0 + + + + 201.0 + + + + 200.0 + + + + 198.0 + + + + 197.0 + + + + 196.0 + + + + 194.0 + + + + 192.0 + + + + 190.0 + + + + 187.0 + + + + 186.0 + + + + 187.0 + + + + 189.0 + + + + 190.0 + + + + 190.0 + + + + 189.0 + + + + 188.0 + + + + 187.0 + + + + 186.0 + + + + 185.0 + + + + 184.0 + + + + 183.0 + + + + 182.0 + + + + 182.0 + + + + 182.0 + + + + 180.0 + + + + 181.0 + + + + 182.0 + + + + 181.0 + + + + 179.0 + + + + 177.0 + + + + 176.0 + + + + 174.0 + + + + 173.0 + + + + 171.0 + + + + 169.0 + + + + 167.0 + + + + 166.0 + + + + 164.0 + + + + 163.0 + + + + 162.0 + + + + 161.0 + + + + 160.0 + + + + 159.0 + + + + 158.0 + + + + 158.0 + + + + 158.0 + + + + 158.0 + + + + 158.0 + + + + 158.0 + + + + 158.0 + + + + 158.0 + + + + 158.0 + + + + 158.0 + + + + 158.0 + + + + 156.0 + + + + 157.0 + + + + 157.0 + + + + 158.0 + + + + 158.0 + + + + 158.0 + + + + 160.0 + + + + 163.0 + + + + 165.0 + + + + 167.0 + + + + 167.0 + + + + 168.0 + + + + 167.0 + + + + 169.0 + + + + 170.0 + + + + 168.0 + + + + 169.0 + + + + 173.0 + + + + 173.0 + + + + 174.0 + + + + 173.0 + + + + 172.0 + + + + 171.0 + + + + 172.0 + + + + 171.0 + + + + 170.0 + + + + 169.0 + + + + 167.0 + + + + 168.0 + + + + 168.0 + + + + 169.0 + + + + 170.0 + + + + 171.0 + + + + 170.0 + + + + 171.0 + + + + 170.0 + + + + 172.0 + + + + 174.0 + + + + 176.0 + + + + 178.0 + + + + 179.0 + + + + 180.0 + + + + 182.0 + + + + 182.0 + + + + 181.0 + + + + 181.0 + + + + 182.0 + + + + 182.0 + + + + 185.0 + + + + 187.0 + + + + 188.0 + + + + 187.0 + + + + 187.0 + + + + 186.0 + + + + 186.0 + + + + 186.0 + + + + 186.0 + + + + 186.0 + + + + 187.0 + + + + 187.0 + + + + 188.0 + + + + 187.0 + + + + 188.0 + + + + 186.0 + + + + 186.0 + + + + 187.0 + + + + 188.0 + + + + 189.0 + + + + 190.0 + + + + 189.0 + + + + 190.0 + + + + 191.0 + + + + 192.0 + + + + 191.0 + + + + 192.0 + + + + 193.0 + + + + 193.0 + + + + 193.0 + + + + 192.0 + + + + 193.0 + + + + 193.0 + + + + 193.0 + + + + 193.0 + + + + 194.0 + + + + 196.0 + + + + 197.0 + + + + 199.0 + + + + 199.0 + + + + 198.0 + + + + 195.0 + + + + 194.0 + + + + 193.0 + + + + 193.0 + + + + 192.0 + + + + 192.0 + + + + 192.0 + + + + 193.0 + + + + 191.0 + + + + 193.0 + + + + 194.0 + + + + 193.0 + + + + 193.0 + + + + 194.0 + + + + 194.0 + + + + 195.0 + + + + 197.0 + + + + 196.0 + + + + 198.0 + + + + 200.0 + + + + 201.0 + + + + 200.0 + + + + 203.0 + + + + 204.0 + + + + 204.0 + + + + 205.0 + + + + 208.0 + + + + 209.0 + + + + 209.0 + + + + 210.0 + + + + 211.0 + + + + 210.0 + + + + 211.0 + + + + 211.0 + + + + 211.0 + + + + 210.0 + + + + 213.0 + + + + 211.0 + + + + 210.0 + + + + 210.0 + + + + 211.0 + + + + 211.0 + + + + 210.0 + + + + 211.0 + + + + 212.0 + + + + 213.0 + + + + 215.0 + + + + 214.0 + + + + 216.0 + + + + 217.0 + + + + 219.0 + + + + 220.0 + + + + 220.0 + + + + 220.0 + + + + 220.0 + + + + 221.0 + + + + 221.0 + + + + 223.0 + + + + 222.0 + + + + 222.0 + + + + 224.0 + + + + 224.0 + + + + 225.0 + + + + 225.0 + + + + 226.0 + + + + 226.0 + + + + 226.0 + + + + 226.0 + + + + 228.0 + + + + 226.0 + + + + 229.0 + + + + 228.0 + + + + 228.0 + + + + 228.0 + + + + 228.0 + + + + 227.0 + + + + 229.0 + + + + 227.0 + + + + 230.0 + + + + 229.0 + + + + 232.0 + + + + 232.0 + + + + 233.0 + + + + 0.0 + + + + 232.0 + + + + 232.0 + + + + 233.0 + + + + 235.0 + + + + 235.0 + + + + 236.0 + + + + 237.0 + + + + 235.0 + + + + 235.0 + + + + 234.0 + + + + 233.0 + + + + 235.0 + + + + 236.0 + + + + 236.0 + + + + 235.0 + + + + 237.0 + + + + 235.0 + + + + 236.0 + + + + 237.0 + + + + 236.0 + + + + 236.0 + + + + 235.0 + + + + 235.0 + + + + 235.0 + + + + 236.0 + + + + 235.0 + + + + 235.0 + + + + 234.0 + + + + 235.0 + + + + 233.0 + + + + 233.0 + + + + 233.0 + + + + 232.0 + + + + 232.0 + + + + 231.0 + + + + 232.0 + + + + 233.0 + + + + 233.0 + + + + 233.0 + + + + 234.0 + + + + 234.0 + + + + 234.0 + + + + 236.0 + + + + 235.0 + + + + 235.0 + + + + 235.0 + + + + 236.0 + + + + 236.0 + + + + 237.0 + + + + 237.0 + + + + 240.0 + + + + 240.0 + + + + 241.0 + + + + 242.0 + + + + 243.0 + + + + 244.0 + + + + 244.0 + + + + 247.0 + + + + 247.0 + + + + 246.0 + + + + 245.0 + + + + 246.0 + + + + 247.0 + + + + 247.0 + + + + 248.0 + + + + 248.0 + + + + 248.0 + + + + 247.0 + + + + 247.0 + + + + 249.0 + + + + 248.0 + + + + 249.0 + + + + 249.0 + + + + 249.0 + + + + 251.0 + + + + 250.0 + + + + 249.0 + + + + 250.0 + + + + 250.0 + + + + 250.0 + + + + 251.0 + + + + 251.0 + + + + 252.0 + + + + 251.0 + + + + 250.0 + + + + 251.0 + + + + 0.0 + + + + 251.0 + + + + 250.0 + + + + 251.0 + + + + 251.0 + + + + 252.0 + + + + 252.0 + + + + 253.0 + + + + 253.0 + + + + 253.0 + + + + 254.0 + + + + 253.0 + + + + 252.0 + + + + 251.0 + + + + 252.0 + + + + 251.0 + + + + 251.0 + + + + 251.0 + + + + 251.0 + + + + 252.0 + + + + 250.0 + + + + 250.0 + + + + 250.0 + + + + 251.0 + + + + 250.0 + + + + 250.0 + + + + 251.0 + + + + 251.0 + + + + 251.0 + + + + 251.0 + + + + 252.0 + + + + 251.0 + + + + 251.0 + + + + 251.0 + + + + 251.0 + + + + 251.0 + + + + 252.0 + + + + 251.0 + + + + 252.0 + + + + 251.0 + + + + 251.0 + + + + 252.0 + + + + 251.0 + + + + 252.0 + + + + 251.0 + + + + 251.0 + + + + 250.0 + + + + 249.0 + + + + 248.0 + + + + 248.0 + + + + 247.0 + + + + 246.0 + + + + 246.0 + + + + 245.0 + + + + 245.0 + + + + 243.0 + + + + 243.0 + + + + 243.0 + + + + 243.0 + + + + 245.0 + + + + 243.0 + + + + 243.0 + + + + 0.0 + + + + 244.0 + + + + 0.0 + + + + 0.0 + + + + 0.0 + + + + 0.0 + + + + 243.0 + + + + 243.0 + + + + 0.0 + + + + 0.0 + + + + 0.0 + + + + 244.0 + + + + 243.0 + + + + 243.0 + + + + 243.0 + + + + 243.0 + + + + 244.0 + + + + 244.0 + + + + 243.0 + + + + 243.0 + + + + 243.0 + + + + 0.0 + + + + 241.0 + + + + 243.0 + + + + 241.0 + + + + 243.0 + + + + 244.0 + + + + 243.0 + + + + 243.0 + + + + 241.0 + + + + 241.0 + + + + 241.0 + + + + 241.0 + + + + 244.0 + + + + 244.0 + + + + 244.0 + + + + 244.0 + + + + 240.0 + + + + 240.0 + + + + 241.0 + + + + 241.0 + + + + 241.0 + + + + 241.0 + + + + 241.0 + + + + 241.0 + + + + 241.0 + + + + 241.0 + + + + 240.0 + + + + 0.0 + + + + diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 5fcd5aa1..ff5ecca1 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -55,6 +55,28 @@ RSpec.describe User, type: :model do end end end + + describe '#import_sample_points' do + before do + stub_const('IMPORT_SAMPLE_POINTS', true) + end + + it 'creates a sample import and enqueues an import job' do + expect do + user = create(:user) + # Explicitly call the method since the callback is disabled in test env + user.send(:import_sample_points) + + # Check if an import was created with the expected name + expect(user.imports.count).to eq(1) + expect(user.imports.first.name).to eq('DELETE_ME_this_is_a_demo_import_DELETE_ME') + expect(user.imports.first.source).to eq('gpx') + + # Check if the ImportJob was enqueued with correct parameters + expect(ImportJob).to have_been_enqueued.with(user.id, user.imports.first.id) + end.to change(Import, :count).by(1) + end + end end describe 'methods' do From 992151c3801040890cda6e39f183318b1f0d7bcc Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Wed, 12 Mar 2025 21:01:03 +0100 Subject: [PATCH 2/3] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ada5cca6..233e03ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ This release is focused on improving the visits experience. - User can now select two or more visits in the visits drawer and merge them into a single visit. This operation is not reversible. - User can now select two or more visits in the visits drawer and confirm or decline them at once. This operation is not reversible. - Status field to the User model. Inactive users are now being restricted from accessing some of the functionality, which is mostly about writing data to the database. Reading is remaining unrestricted. +- After user is created, a sample import is being created for them to demonstrate how to use the app. ## Changed From d4503083bc3bf5bd80386e681a5b595568da5ed2 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Wed, 12 Mar 2025 21:19:48 +0100 Subject: [PATCH 3/3] Fix sample points import --- spec/models/user_spec.rb | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index ff5ecca1..6fecebfd 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -58,23 +58,21 @@ RSpec.describe User, type: :model do describe '#import_sample_points' do before do - stub_const('IMPORT_SAMPLE_POINTS', true) + ENV['IMPORT_SAMPLE_POINTS'] = 'true' + end + + after do + ENV['IMPORT_SAMPLE_POINTS'] = nil end it 'creates a sample import and enqueues an import job' do - expect do - user = create(:user) - # Explicitly call the method since the callback is disabled in test env - user.send(:import_sample_points) + user = create(:user) - # Check if an import was created with the expected name - expect(user.imports.count).to eq(1) - expect(user.imports.first.name).to eq('DELETE_ME_this_is_a_demo_import_DELETE_ME') - expect(user.imports.first.source).to eq('gpx') + expect(user.imports.count).to eq(1) + expect(user.imports.first.name).to eq('DELETE_ME_this_is_a_demo_import_DELETE_ME') + expect(user.imports.first.source).to eq('gpx') - # Check if the ImportJob was enqueued with correct parameters - expect(ImportJob).to have_been_enqueued.with(user.id, user.imports.first.id) - end.to change(Import, :count).by(1) + expect(ImportJob).to have_been_enqueued.with(user.id, user.imports.first.id) end end end