From d8df32b470a14fb28f4b7d273af30221dfe5da28 Mon Sep 17 00:00:00 2001 From: andrea longhi Date: Wed, 1 Mar 2023 16:46:20 +0100 Subject: [PATCH] Add back Variant#find_or_build_default_price This method was renamed to `default_price_or_build` with 6420b10, but this was a breaking change given it was released with Solidus 3.1. This commit reintroduces the method as an alias but with deprecation. --- core/app/models/concerns/spree/default_price.rb | 5 +++++ core/spec/models/spree/variant_spec.rb | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/core/app/models/concerns/spree/default_price.rb b/core/app/models/concerns/spree/default_price.rb index f638d54bb84..e2c50252849 100644 --- a/core/app/models/concerns/spree/default_price.rb +++ b/core/app/models/concerns/spree/default_price.rb @@ -32,6 +32,11 @@ def default_price_or_build prices.build(self.class.default_price_attributes) end + def find_or_build_default_price + default_price_or_build + end + deprecate :find_or_build_default_price, deprecator: Spree::Deprecation + # Select from {#prices} the one to be considered as the default # # This method works with the in-memory association, so non-persisted prices diff --git a/core/spec/models/spree/variant_spec.rb b/core/spec/models/spree/variant_spec.rb index cc0fe73c15c..66c95b09da9 100644 --- a/core/spec/models/spree/variant_spec.rb +++ b/core/spec/models/spree/variant_spec.rb @@ -334,6 +334,21 @@ end end + describe '#find_or_build_default_price' do + it 'is deprecated' do + without_partial_double_verification do + expect(Spree::Deprecation).to receive(:warn) + end + variant.find_or_build_default_price + end + + it 'is an alias for #default_price_or_build' do + expect(variant).to receive(:default_price_or_build) + + variant.find_or_build_default_price + end + end + describe '#has_default_price?' do context 'when default price is present and not discarded' do it 'returns true' do