Use enum-generated scopes/queries for `BulkImport` (#29975)

This commit is contained in:
Matt Jankowski 2024-04-18 06:13:35 -04:00 committed by GitHub
parent 630572323f
commit 11e0049b08
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 9 additions and 9 deletions

View File

@ -31,7 +31,7 @@ class Settings::ImportsController < Settings::BaseController
def show; end
def failures
@bulk_import = current_account.bulk_imports.where(state: :finished).find(params[:id])
@bulk_import = current_account.bulk_imports.state_finished.find(params[:id])
respond_to do |format|
format.csv do
@ -92,7 +92,7 @@ class Settings::ImportsController < Settings::BaseController
end
def set_bulk_import
@bulk_import = current_account.bulk_imports.where(state: :unconfirmed).find(params[:id])
@bulk_import = current_account.bulk_imports.state_unconfirmed.find(params[:id])
end
def set_recent_imports

View File

@ -9,7 +9,7 @@ class Vacuum::ImportsVacuum
private
def clean_unconfirmed_imports!
BulkImport.where(state: :unconfirmed).where('created_at <= ?', 10.minutes.ago).reorder(nil).in_batches.delete_all
BulkImport.state_unconfirmed.where('created_at <= ?', 10.minutes.ago).reorder(nil).in_batches.delete_all
end
def clean_old_imports!

View File

@ -38,7 +38,7 @@ class BulkImport < ApplicationRecord
scheduled: 1,
in_progress: 2,
finished: 3,
}
}, prefix: true
validates :type, presence: true

View File

@ -49,7 +49,7 @@
%tr
%td= t("imports.types.#{import.type}")
%td
- if import.unconfirmed?
- if import.state_unconfirmed?
= link_to t("imports.states.#{import.state}"), settings_import_path(import)
- else
= t("imports.states.#{import.state}")
@ -59,7 +59,7 @@
%td
- num_failed = import.processed_items - import.imported_items
- if num_failed.positive?
- if import.finished?
- if import.state_finished?
= link_to num_failed, failures_settings_import_path(import, format: 'csv')
- else
= num_failed

View File

@ -281,7 +281,7 @@ RSpec.describe Form::Import do
end
it 'defaults to unconfirmed true' do
expect(bulk_import.unconfirmed?).to be true
expect(bulk_import.state_unconfirmed?).to be true
end
end
end

View File

@ -291,7 +291,7 @@ RSpec.describe BulkImportService do
it 'marks the import as finished' do
subject.call(import)
expect(import.reload.finished?).to be true
expect(import.reload.state_finished?).to be true
end
end
@ -319,7 +319,7 @@ RSpec.describe BulkImportService do
it 'marks the import as finished' do
subject.call(import)
expect(import.reload.finished?).to be true
expect(import.reload.state_finished?).to be true
end
end