Skip to content

Commit

Permalink
Add back Variant#find_or_build_default_price
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
spaghetticode committed Mar 1, 2023
1 parent 6d55800 commit d8df32b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 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,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
Expand Down
15 changes: 15 additions & 0 deletions core/spec/models/spree/variant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d8df32b

Please sign in to comment.