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

main
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 show; end
def failures 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| respond_to do |format|
format.csv do format.csv do
@ -92,7 +92,7 @@ class Settings::ImportsController < Settings::BaseController
end end
def set_bulk_import 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 end
def set_recent_imports def set_recent_imports

View File

@ -9,7 +9,7 @@ class Vacuum::ImportsVacuum
private private
def clean_unconfirmed_imports! 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 end
def clean_old_imports! def clean_old_imports!

View File

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

View File

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

View File

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

View File

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