Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add back Variant#find_or_build_default_price #4960

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -334,6 +334,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