From 5846225f94288af148808ccb94f49a8228fc3bc8 Mon Sep 17 00:00:00 2001 From: andrea longhi Date: Mon, 8 Aug 2022 12:31:00 +0200 Subject: [PATCH] Include discarded prices in delete_prices_with_nil_amount task The task is currently removing only non-discarded prices. We should remove discarded prices as well, otherwise the migration path from https://github.com/solidusio/solidus/blob/master/CHANGELOG.md#solidus-310-v31-2021-09-10 may fail. --- core/lib/tasks/solidus/delete_prices_with_nil_amount.rake | 4 ++-- .../lib/tasks/solidus/delete_prices_with_nil_amount_spec.rb | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/core/lib/tasks/solidus/delete_prices_with_nil_amount.rake b/core/lib/tasks/solidus/delete_prices_with_nil_amount.rake index abc328d3105..2bae8deab0f 100644 --- a/core/lib/tasks/solidus/delete_prices_with_nil_amount.rake +++ b/core/lib/tasks/solidus/delete_prices_with_nil_amount.rake @@ -1,8 +1,8 @@ # frozen_string_literal: true namespace :solidus do - desc "Delete Spree::Price records which amount field is NULL" + desc "Delete Spree::Price records (including discarded) which amount field is NULL" task delete_prices_with_nil_amount: :environment do - Spree::Price.where(amount: nil).delete_all + Spree::Price.with_discarded.where(amount: nil).delete_all end end diff --git a/core/spec/lib/tasks/solidus/delete_prices_with_nil_amount_spec.rb b/core/spec/lib/tasks/solidus/delete_prices_with_nil_amount_spec.rb index e875b1acb8c..4b59790a98f 100644 --- a/core/spec/lib/tasks/solidus/delete_prices_with_nil_amount_spec.rb +++ b/core/spec/lib/tasks/solidus/delete_prices_with_nil_amount_spec.rb @@ -14,7 +14,9 @@ it 'removes all prices which amount column is NULL' do price = create(:price) - expect(Spree::Price).to receive(:where).with(amount: nil).and_return(Spree::Price.where(id: price)) + with_discarded = instance_double("Spree::Price::ActiveRecord_Relation", where: Spree::Price.where(id: price)) + + expect(Spree::Price).to receive(:with_discarded) { with_discarded } task.invoke