Skip to content

Commit

Permalink
Merge pull request solidusio#4963 from solidusio/backport/v3.1/pr-4960
Browse files Browse the repository at this point in the history
[v3.1] Add back Variant#find_or_build_default_price
  • Loading branch information
waiting-for-dev authored Mar 2, 2023
2 parents 5417fea + 4fa1500 commit 0cd3541
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions core/app/models/concerns/spree/default_price.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ def default_price_or_build
prices.build(self.class.default_price_attributes)
end

# @deprecated Use {#default_price_or_build} instead.
def find_or_build_default_price
default_price_or_build
end
deprecate find_or_build_default_price: :default_price_or_build, 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
Expand Down
19 changes: 19 additions & 0 deletions core/spec/models/spree/variant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,25 @@
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
without_partial_double_verification do
allow(Spree::Deprecation).to receive(:warn)
end

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
Expand Down

0 comments on commit 0cd3541

Please sign in to comment.