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

Deprecate unused calculators #3863

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
1 change: 1 addition & 0 deletions core/app/models/spree/calculator/free_shipping.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module Spree
# now a Promotion Action which deals with these types of promotions instead.
class Calculator::FreeShipping < Calculator
def compute(object)
Spree::Deprecation.warn('This method is deprecated, because it is no longer used')
if object.is_a?(Array)
return if object.empty?
order = object.first.order
Expand Down
2 changes: 2 additions & 0 deletions core/app/models/spree/calculator/percent_per_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class Calculator::PercentPerItem < Calculator
preference :percent, :decimal, default: 0

def compute(object = nil)
Spree::Deprecation.warn('This method is deprecated, please use adjustments at line item level')

return 0 if object.nil?
object.line_items.sum { |line_item|
value_for_line_item(line_item)
Expand Down
1 change: 1 addition & 0 deletions core/app/models/spree/calculator/price_sack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Calculator::PriceSack < Calculator

# as object we always get line items, as calculable we have Coupon, ShippingMethod
def compute(object)
Spree::Deprecation.warn('This method is deprecated, please use adjustments at line item level')
if object.is_a?(Array)
base = object.sum { |element| element.respond_to?(:amount) ? element.amount : BigDecimal(element.to_s) }
else
Expand Down
12 changes: 12 additions & 0 deletions core/spec/models/spree/calculator/free_shipping_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,16 @@

RSpec.describe Spree::Calculator::FreeShipping, type: :model do
it_behaves_like 'a calculator with a description'

describe '#compute' do
let(:order) { stub_model(Spree::Order) }

before do
expect(Spree::Deprecation).to receive(:warn).with(/method is deprecated/)
end

it 'warns about deprecation' do
described_class.new.compute(order)
end
end
end
12 changes: 12 additions & 0 deletions core/spec/models/spree/calculator/percent_per_item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,17 @@
module Spree
RSpec.describe Calculator::PercentPerItem, type: :model do
it_behaves_like 'a calculator with a description'

describe '#compute' do
let(:order) { stub_model(Spree::Order) }

before do
expect(Spree::Deprecation).to receive(:warn).with(/method is deprecated/)
end

it 'warns about deprecation' do
described_class.new.compute(order)
end
end
end
end
34 changes: 20 additions & 14 deletions core/spec/models/spree/calculator/price_sack_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,28 @@

it_behaves_like 'a calculator with a description'

let(:order) { stub_model(Spree::Order) }
let(:shipment) { stub_model(Spree::Shipment, amount: 10) }
describe '#compute' do
let(:order) { stub_model(Spree::Order) }
let(:shipment) { stub_model(Spree::Shipment, amount: 10) }

# Regression test for https://github.com/spree/spree/issues/714 and https://github.com/spree/spree/issues/739
it "computes with an order object" do
calculator.compute(order)
end
before do
expect(Spree::Deprecation).to receive(:warn).with(/method is deprecated/).at_least(1)
end

# Regression test for https://github.com/spree/spree/issues/1156
it "computes with a shipment object" do
calculator.compute(shipment)
end
# Regression test for https://github.com/spree/spree/issues/714 and https://github.com/spree/spree/issues/739
it "computes with an order object" do
calculator.compute(order)
end

# Regression test for https://github.com/spree/spree/issues/1156
it "computes with a shipment object" do
calculator.compute(shipment)
end

# Regression test for https://github.com/spree/spree/issues/2055
it "computes the correct amount" do
expect(calculator.compute(2)).to eq(calculator.preferred_normal_amount)
expect(calculator.compute(6)).to eq(calculator.preferred_discount_amount)
# Regression test for https://github.com/spree/spree/issues/2055
it "computes the correct amount" do
expect(calculator.compute(2)).to eq(calculator.preferred_normal_amount)
expect(calculator.compute(6)).to eq(calculator.preferred_discount_amount)
end
end
end