dawarich/spec/models/export_spec.rb

50 lines
1.3 KiB
Ruby
Raw Permalink Normal View History

2024-06-12 14:29:38 -04:00
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Export, type: :model do
describe 'associations' do
it { is_expected.to belong_to(:user) }
end
describe 'enums' do
it { is_expected.to define_enum_for(:status).with_values(created: 0, processing: 1, completed: 2, failed: 3) }
2025-06-26 13:24:40 -04:00
it { is_expected.to define_enum_for(:file_format).with_values(json: 0, gpx: 1, archive: 2) }
2025-06-26 13:48:42 -04:00
it { is_expected.to define_enum_for(:file_type).with_values(points: 0, user_data: 1) }
end
describe 'callbacks' do
describe 'after_commit' do
context 'when the export is created' do
2025-06-26 14:05:26 -04:00
let(:export) { build(:export, file_type: :points) }
2025-06-26 13:48:42 -04:00
it 'enqueues the ExportJob' do
2025-06-26 14:05:26 -04:00
expect(ExportJob).to receive(:perform_later)
2025-06-26 13:48:42 -04:00
export.save!
end
context 'when the export is a user data export' do
let(:export) { build(:export, file_type: :user_data) }
it 'does not enqueue the ExportJob' do
expect(ExportJob).not_to receive(:perform_later).with(export.id)
export.save!
end
end
end
context 'when the export is destroyed' do
let(:export) { create(:export) }
it 'removes the attached file' do
2025-06-26 14:05:26 -04:00
expect(export.file).to receive(:purge_later)
2025-06-26 13:48:42 -04:00
export.destroy!
end
end
end
2024-06-12 14:29:38 -04:00
end
end