From 11e0049b08c721eb98d8220405c2ffc16041ed17 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Thu, 18 Apr 2024 06:13:35 -0400 Subject: [PATCH] Use enum-generated scopes/queries for `BulkImport` (#29975) --- app/controllers/settings/imports_controller.rb | 4 ++-- app/lib/vacuum/imports_vacuum.rb | 2 +- app/models/bulk_import.rb | 2 +- app/views/settings/imports/index.html.haml | 4 ++-- spec/models/form/import_spec.rb | 2 +- spec/services/bulk_import_service_spec.rb | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/controllers/settings/imports_controller.rb b/app/controllers/settings/imports_controller.rb index 983caf22f..569aa07c5 100644 --- a/app/controllers/settings/imports_controller.rb +++ b/app/controllers/settings/imports_controller.rb @@ -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 diff --git a/app/lib/vacuum/imports_vacuum.rb b/app/lib/vacuum/imports_vacuum.rb index ffb9449a4..8c8bb783a 100644 --- a/app/lib/vacuum/imports_vacuum.rb +++ b/app/lib/vacuum/imports_vacuum.rb @@ -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! diff --git a/app/models/bulk_import.rb b/app/models/bulk_import.rb index 4cd228705..9b3f4c8a3 100644 --- a/app/models/bulk_import.rb +++ b/app/models/bulk_import.rb @@ -38,7 +38,7 @@ class BulkImport < ApplicationRecord scheduled: 1, in_progress: 2, finished: 3, - } + }, prefix: true validates :type, presence: true diff --git a/app/views/settings/imports/index.html.haml b/app/views/settings/imports/index.html.haml index d5ca252dc..ca815720f 100644 --- a/app/views/settings/imports/index.html.haml +++ b/app/views/settings/imports/index.html.haml @@ -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 diff --git a/spec/models/form/import_spec.rb b/spec/models/form/import_spec.rb index c2f41d442..22ffdfd87 100644 --- a/spec/models/form/import_spec.rb +++ b/spec/models/form/import_spec.rb @@ -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 diff --git a/spec/services/bulk_import_service_spec.rb b/spec/services/bulk_import_service_spec.rb index c3a716058..e8bec96c8 100644 --- a/spec/services/bulk_import_service_spec.rb +++ b/spec/services/bulk_import_service_spec.rb @@ -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