Merge pull request #2811 from luisramos0/2-0-adjust-basic-spec-fix

[Spree Upgrade] Fixes shipping tests in adjustment spec
This commit is contained in:
Maikel
2018-10-18 14:49:28 +11:00
committed by GitHub
5 changed files with 22 additions and 35 deletions

View File

@@ -8,19 +8,18 @@ module Spree
alias_method_chain :match, :sales_tax_registration
end
def adjust_with_included_tax(order)
adjust_without_included_tax(order)
order.adjustments(:reload)
order.line_items(:reload)
(order.adjustments.tax + order.price_adjustments).each do |a|
a.set_absolute_included_tax! a.amount
# TaxRate adjustments (order.adjustments.tax) and price adjustments (tax included on line items) consist of 100% tax
(order.adjustments.tax + order.price_adjustments).each do |adjustment|
adjustment.set_absolute_included_tax! adjustment.amount
end
end
alias_method_chain :adjust, :included_tax
# Manually apply a TaxRate to a particular amount. TaxRates normally compute against
# LineItems or Orders, so we mock out a line item here to fit the interface
# that our calculator (usually DefaultTax) expects.
@@ -40,7 +39,6 @@ module Spree
end
end
private
def with_tax_included_in_price

View File

@@ -7,7 +7,6 @@
# config.setting_name = 'new value'
require 'spree/product_filters'
require 'spree/core/calculated_adjustments_decorator'
require "#{Rails.root}/app/models/spree/payment_method_decorator"
require "#{Rails.root}/app/models/spree/gateway_decorator"

View File

@@ -1,16 +0,0 @@
module Spree
module Core
module CalculatedAdjustments
class << self
def included_with_explicit_class_name(klass)
included_without_explicit_class_name(klass)
klass.class_eval do
has_one :calculator, as: :calculable, dependent: :destroy, class_name: 'Spree::Calculator'
end
end
alias_method_chain :included, :explicit_class_name
end
end
end
end

View File

@@ -378,7 +378,7 @@ FactoryBot.define do
shipping_method { create(:shipping_method) }
end
after(:create) do |shipment, evaluator|
shipment.shipping_rates.destroy_all # remove existing shipping_rates from shipment
shipment.shipping_rates.destroy_all
shipment.add_shipping_method(evaluator.shipping_method, true)
end
end
@@ -390,7 +390,7 @@ FactoryBot.define do
after(:create) do |shipment, evaluator|
shipping_method = create(:shipping_method_with, :shipping_fee, shipping_fee: evaluator.shipping_fee)
shipment.shipping_rates.destroy_all # remove existing shipping_rates from shipment
shipment.shipping_rates.destroy_all
shipment.add_shipping_method(shipping_method, true)
end
end

View File

@@ -61,38 +61,43 @@ module Spree
describe "Shipment adjustments" do
let(:shipping_method) { create(:shipping_method_with, :flat_rate) }
let(:shipment) { create(:shipment_with, :shipping_method, shipping_method: shipping_method) }
let!(:order) { create(:order, distributor: hub, shipments: [shipment]) }
let(:order) { create(:order, distributor: hub) }
let(:hub) { create(:distributor_enterprise, charges_sales_tax: true) }
let!(:line_item) { create(:line_item, order: order) }
let(:line_item) { create(:line_item, order: order) }
let(:adjustment) { order.adjustments(:reload).shipping.first }
it "has a shipping charge of $50" do
adjustment.amount.should == 50
describe "the shipping charge" do
it "is the adjustment amount" do
order.shipments = [shipment]
adjustment.amount.should == 50
end
end
describe "when tax on shipping is disabled" do
before { Config.shipment_inc_vat = false }
it "records 0% tax on shipment adjustments" do
Config.shipment_inc_vat = false
Config.shipping_tax_rate = 0
order.shipments = [shipment]
adjustment.included_tax.should == 0
end
it "records 0% tax on shipments when a rate is set but shipment_inc_vat is false" do
Config.shipment_inc_vat = false
Config.shipping_tax_rate = 0.25
order.shipments = [shipment]
adjustment.included_tax.should == 0
end
end
describe "when tax on shipping is enabled" do
before do
Config.shipment_inc_vat = true
Config.shipping_tax_rate = 0.25
end
before { Config.shipment_inc_vat = true }
it "takes the shipment adjustment tax included from the system setting" do
Config.shipping_tax_rate = 0.25
order.shipments = [shipment]
# Finding the tax included in an amount that's already inclusive of tax:
# total - ( total / (1 + rate) )
# 50 - ( 50 / (1 + 0.25) )
@@ -101,14 +106,15 @@ module Spree
end
it "records 0% tax on shipments when shipping_tax_rate is not set" do
Config.shipment_inc_vat = true
Config.shipping_tax_rate = nil
order.shipments = [shipment]
adjustment.included_tax.should == 0
end
it "records 0% tax on shipments when the distributor does not charge sales tax" do
order.distributor.update_attributes! charges_sales_tax: false
order.shipments = [shipment]
adjustment.included_tax.should == 0
end