Skip to content

Commit

Permalink
Merge pull request solidusio#3863 from DanielePalombo/danielepalombo/…
Browse files Browse the repository at this point in the history
…deprecate-useless-methods

Deprecate unused calculators
  • Loading branch information
kennyadsl authored Dec 16, 2020
2 parents 20f6451 + 804da3b commit c7025ee
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 14 deletions.
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

0 comments on commit c7025ee

Please sign in to comment.