From c8cfbbb0b2448560ecc9a5641a52286539832599 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 29 Sep 2022 11:56:10 +1000 Subject: [PATCH] Use standard ApplicationRecord in task class It's best practice to use the ApplicationRecord. But when Rake is loaded, our application is not loaded yet and the ApplicationRecord class wasn't available yet. Requiring within the task solves the problem because Rake loads the Rails environment before executing this task. I also removed the unused highline loading. --- .rubocop_todo.yml | 6 ------ lib/tasks/data/remove_transient_data.rake | 4 +--- lib/tasks/data/remove_transient_data.rb | 2 +- 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 72e4621f40..46dfffca7b 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -699,12 +699,6 @@ Rails/ApplicationMailer: Exclude: - 'app/mailers/spree/base_mailer.rb' -# Offense count: 1 -# This cop supports unsafe autocorrection (--autocorrect-all). -Rails/ApplicationRecord: - Exclude: - - 'lib/tasks/data/remove_transient_data.rb' - # Offense count: 5 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: NilOrEmpty, NotPresent, UnlessPresent. diff --git a/lib/tasks/data/remove_transient_data.rake b/lib/tasks/data/remove_transient_data.rake index 2a2d8d2180..5f5cd7449e 100644 --- a/lib/tasks/data/remove_transient_data.rake +++ b/lib/tasks/data/remove_transient_data.rake @@ -1,12 +1,10 @@ # frozen_string_literal: true -require 'highline' -require 'tasks/data/remove_transient_data' - namespace :ofn do namespace :data do desc 'Remove transient data' task remove_transient_data: :environment do + require 'tasks/data/remove_transient_data' RemoveTransientData.new.call end end diff --git a/lib/tasks/data/remove_transient_data.rb b/lib/tasks/data/remove_transient_data.rb index 9c77d7aa5e..08411af0c4 100644 --- a/lib/tasks/data/remove_transient_data.rb +++ b/lib/tasks/data/remove_transient_data.rb @@ -6,7 +6,7 @@ class RemoveTransientData # This model lets us operate on the sessions DB table using ActiveRecord's # methods within the scope of this service. This relies on the AR's # convention where a Session model maps to a sessions table. - class Session < ActiveRecord::Base + class Session < ApplicationRecord end def call