mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-10 17:21:38 -05:00
Update specs
This commit is contained in:
parent
8dd7ba8363
commit
4898cd82ac
5 changed files with 13 additions and 11 deletions
|
|
@ -4,6 +4,8 @@ class ExceptionReporter
|
|||
def self.call(exception)
|
||||
return unless DawarichSettings.self_hosted?
|
||||
|
||||
Rails.logger.error "Exception: #{exception.message}"
|
||||
|
||||
Sentry.capture_exception(exception)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -280,7 +280,9 @@ class Users::ExportData
|
|||
rescue StandardError => e
|
||||
# Mark export as failed if an error occurs
|
||||
export_record.update!(status: :failed) if export_record
|
||||
Rails.logger.error "Export failed: #{e.message}"
|
||||
|
||||
ExceptionReporter.call(e)
|
||||
|
||||
raise e
|
||||
ensure
|
||||
# Cleanup temporary files
|
||||
|
|
@ -332,8 +334,7 @@ class Users::ExportData
|
|||
Rails.logger.info "Cleaning up temporary export directory: #{export_directory}"
|
||||
FileUtils.rm_rf(export_directory)
|
||||
rescue StandardError => e
|
||||
Rails.logger.error "Failed to cleanup temporary files: #{e.message}"
|
||||
# Don't re-raise the error as cleanup failure shouldn't break the export
|
||||
ExceptionReporter.call(e)
|
||||
end
|
||||
|
||||
def create_success_notification
|
||||
|
|
|
|||
|
|
@ -51,7 +51,8 @@ class Users::ExportData::Exports
|
|||
download_and_save_export_file(export, file_path)
|
||||
add_file_metadata_to_export(export, export_hash, sanitized_filename)
|
||||
rescue StandardError => e
|
||||
Rails.logger.error "Failed to download export file #{export.id}: #{e.message}"
|
||||
ExceptionReporter.call(e)
|
||||
|
||||
export_hash['file_error'] = "Failed to download: #{e.message}"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -51,7 +51,8 @@ class Users::ExportData::Imports
|
|||
download_and_save_import_file(import, file_path)
|
||||
add_file_metadata_to_import(import, import_hash, sanitized_filename)
|
||||
rescue StandardError => e
|
||||
Rails.logger.error "Failed to download import file #{import.id}: #{e.message}"
|
||||
ExceptionReporter.call(e)
|
||||
|
||||
import_hash['file_error'] = "Failed to download: #{e.message}"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,11 +6,12 @@ RSpec.describe Users::ExportData::Areas, type: :service do
|
|||
let(:user) { create(:user) }
|
||||
let(:service) { described_class.new(user) }
|
||||
|
||||
subject { service.call }
|
||||
|
||||
describe '#call' do
|
||||
context 'when user has no areas' do
|
||||
it 'returns an empty array' do
|
||||
result = service.call
|
||||
expect(result).to eq([])
|
||||
expect(subject).to eq([])
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -18,8 +19,6 @@ RSpec.describe Users::ExportData::Areas, type: :service do
|
|||
let!(:area1) { create(:area, user: user, name: 'Home', radius: 100) }
|
||||
let!(:area2) { create(:area, user: user, name: 'Work', radius: 200) }
|
||||
|
||||
subject { service.call }
|
||||
|
||||
it 'returns all user areas' do
|
||||
expect(subject).to be_an(Array)
|
||||
expect(subject.size).to eq(2)
|
||||
|
|
@ -49,8 +48,6 @@ RSpec.describe Users::ExportData::Areas, type: :service do
|
|||
let!(:user_area) { create(:area, user: user, name: 'User Area') }
|
||||
let!(:other_user_area) { create(:area, user: other_user, name: 'Other User Area') }
|
||||
|
||||
subject { service.call }
|
||||
|
||||
it 'only returns areas for the specified user' do
|
||||
expect(subject.size).to eq(1)
|
||||
expect(subject.first['name']).to eq('User Area')
|
||||
|
|
|
|||
Loading…
Reference in a new issue