diff --git a/app/services/imports/source_detector.rb b/app/services/imports/source_detector.rb index c6c2844f..d5b0a2c6 100644 --- a/app/services/imports/source_detector.rb +++ b/app/services/imports/source_detector.rb @@ -118,12 +118,8 @@ class Imports::SourceDetector end def kml_file? - return false unless filename + return false unless filename&.downcase&.end_with?('.kml', '.kmz') - # Must have .kml or .kmz extension AND contain KML XML structure - return false unless filename.downcase.end_with?('.kml', '.kmz') - - # Check content for KML structure content_to_check = if file_path && File.exist?(file_path) # Read first 1KB for KML detection diff --git a/config/environments/production.rb b/config/environments/production.rb index 146ec651..8dd9762f 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -73,7 +73,10 @@ Rails.application.configure do config.log_level = ENV.fetch('RAILS_LOG_LEVEL', 'info') # Use a different cache store in production. - config.cache_store = :redis_cache_store, { url: "#{ENV['REDIS_URL']}/#{ENV.fetch('RAILS_CACHE_DB', 0)}" } + config.cache_store = :redis_cache_store, { + url: ENV['REDIS_URL'], + db: ENV.fetch('RAILS_CACHE_DB', 0) + } # Use a real queuing backend for Active Job (and separate queues per environment). config.active_job.queue_adapter = :sidekiq diff --git a/spec/services/imports/source_detector_spec.rb b/spec/services/imports/source_detector_spec.rb index e3cba810..0f3766c4 100644 --- a/spec/services/imports/source_detector_spec.rb +++ b/spec/services/imports/source_detector_spec.rb @@ -74,6 +74,15 @@ RSpec.describe Imports::SourceDetector do end end + context 'with KML file' do + let(:file_content) { file_fixture('kml/points_with_timestamps.kml').read } + let(:filename) { 'test.kml' } + + it 'detects kml format' do + expect(detector.detect_source).to eq(:kml) + end + end + context 'with invalid JSON' do let(:file_content) { 'invalid json content' } @@ -145,6 +154,15 @@ RSpec.describe Imports::SourceDetector do expect(detector.detect_source).to eq(:geojson) end end + + context 'with KML file' do + let(:fixture_path) { file_fixture('kml/points_with_timestamps.kml').to_s } + + it 'detects source correctly from file path' do + detector = described_class.new_from_file_header(fixture_path) + expect(detector.detect_source).to eq(:kml) + end + end end describe 'detection accuracy with real fixture files' do @@ -170,5 +188,11 @@ RSpec.describe Imports::SourceDetector do include_examples 'detects format correctly', :gpx, 'gpx/arc_example.gpx' include_examples 'detects format correctly', :gpx, 'gpx/garmin_example.gpx' include_examples 'detects format correctly', :gpx, 'gpx/gpx_track_multiple_segments.gpx' + + # Test KML files + include_examples 'detects format correctly', :kml, 'kml/points_with_timestamps.kml' + include_examples 'detects format correctly', :kml, 'kml/linestring_track.kml' + include_examples 'detects format correctly', :kml, 'kml/gx_track.kml' + include_examples 'detects format correctly', :kml, 'kml/multigeometry.kml' end end