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