Skip to content

Commit

Permalink
Remove deprecated method Spree::TaxRate#adjust
Browse files Browse the repository at this point in the history
in favour of Spree::Tax::orderAdjuster#adjust!

solidusio#3354
  • Loading branch information
DanielePalombo authored and kennyadsl committed Nov 27, 2020
1 parent 16d4536 commit 9fc19fa
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 109 deletions.
17 changes: 0 additions & 17 deletions core/app/models/spree/tax_rate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,23 +87,6 @@ class TaxRate < Spree::Base
end
scope :included_in_price, -> { where(included_in_price: true) }

# Creates necessary tax adjustments for the order.
#
# @deprecated Please use `Spree::Tax::OrderAdjuster#adjust!` instead
def adjust(_order_tax_zone, item)
Spree::Deprecation.warn("`Spree::TaxRate#adjust` is deprecated. Please use `Spree::Tax::OrderAdjuster#adjust!` instead.", caller)

amount = compute_amount(item)

item.adjustments.create!(
source: self,
amount: amount,
order_id: item.order_id,
label: adjustment_label(amount),
included: included_in_price
)
end

# This method is used by Adjustment#update to recalculate the cost.
def compute_amount(item)
calculator.compute(item)
Expand Down
92 changes: 0 additions & 92 deletions core/spec/models/spree/tax_rate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,98 +187,6 @@
end
end

describe "#adjust" do
let(:taxable_address) { create(:address) }
let(:order) { create(:order_with_line_items, ship_address: order_address) }
let(:tax_zone) { create(:zone, countries: [taxable_address.country]) }
let(:foreign_address) { create(:address, country_iso_code: "CA") }
let!(:foreign_zone) { create(:zone, countries: [foreign_address.country]) }
let(:tax_rate) do
create(:tax_rate,
included_in_price: included_in_price,
show_rate_in_label: show_rate_in_label,
amount: 0.125,
zone: tax_zone)
end

let(:item) { order.line_items.first }

before do
expect(Spree::Deprecation).to receive(:warn).
with(/^`Spree::TaxRate#adjust` is deprecated/, any_args)
end

describe 'adjustments' do
before do
tax_rate.adjust(nil, item)
end

let(:adjustment_label) { item.adjustments.tax.first.label }

context 'for included rates' do
let(:included_in_price) { true }
let(:order_address) { taxable_address }

context 'with show rate in label' do
let(:show_rate_in_label) { true }

it 'shows the rate in the label' do
expect(adjustment_label).to include("12.500%")
end

it 'adds a remark that the rate is included in the price' do
expect(adjustment_label).to include("Included in Price")
end
end

context 'with show rate in label turned off' do
let(:show_rate_in_label) { false }

it 'does not show the rate in the label' do
expect(adjustment_label).not_to include("12.500%")
end

it 'does not have two consecutive spaces' do
expect(adjustment_label).not_to include(" ")
end

it 'adds a remark that the rate is included in the price' do
expect(adjustment_label).to include("Included in Price")
end
end
end

context 'for additional rates' do
let(:included_in_price) { false }
let(:order_address) { taxable_address }

context 'with show rate in label' do
let(:show_rate_in_label) { true }

it 'shows the rate in the label' do
expect(adjustment_label).to include("12.500%")
end

it 'does not add a remark that the rate is included in the price' do
expect(adjustment_label).not_to include("Included in Price")
end
end

context 'with show rate in label turned off' do
let(:show_rate_in_label) { false }

it 'does not show the rate in the label' do
expect(adjustment_label).not_to include("12.500%")
end

it 'does not add a remark that the rate is included in the price' do
expect(adjustment_label).not_to include("Included in Price")
end
end
end
end
end

describe "#active?" do
subject(:rate) { create(:tax_rate, validity).active? }

Expand Down

0 comments on commit 9fc19fa

Please sign in to comment.