Skip to content

Commit

Permalink
Update specs to reflect the TaxCategory-TaxRate change
Browse files Browse the repository at this point in the history
  • Loading branch information
vladstoick committed Apr 21, 2017
1 parent d806cd1 commit d8bb9e9
Show file tree
Hide file tree
Showing 17 changed files with 90 additions and 42 deletions.
8 changes: 4 additions & 4 deletions core/spec/lib/spree/core/price_migrator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
name: "German reduced VAT",
included_in_price: true,
amount: 0.07,
tax_category: books_category,
tax_categories: [books_category],
zone: eu_zone
)
end
Expand All @@ -65,7 +65,7 @@
name: "German VAT",
included_in_price: true,
amount: 0.19,
tax_category: normal_category,
tax_categories: [normal_category],
zone: eu_zone
)
end
Expand All @@ -75,7 +75,7 @@
name: "German VAT",
included_in_price: true,
amount: 0.19,
tax_category: digital_category,
tax_categories: [digital_category],
zone: germany_zone
)
end
Expand All @@ -85,7 +85,7 @@
name: "Romanian VAT",
included_in_price: true,
amount: 0.24,
tax_category: digital_category,
tax_categories: [digital_category],
zone: romania_zone
)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
context 'when shipments should be taxed' do
let!(:ship_address) { create(:address) }
let!(:tax_zone) { create(:global_zone) } # will include the above address
let!(:tax_rate) { create(:tax_rate, amount: 0.10, zone: tax_zone, tax_category: tax_category) }
let!(:tax_rate) { create(:tax_rate, amount: 0.10, zone: tax_zone, tax_categories: [tax_category]) }

let(:tax_category) { create(:tax_category) }
let(:shipping_method) { create(:shipping_method, tax_category: tax_category, zones: [tax_zone]) }
Expand Down
2 changes: 1 addition & 1 deletion core/spec/models/spree/calculator/default_tax_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
let!(:zone) { create(:zone, name: "Country Zone", default_tax: default_tax, countries: [tax_rate_country]) }
let(:tax_rate_country) { address.country }
let(:tax_category) { create(:tax_category) }
let!(:rate) { create(:tax_rate, tax_category: tax_category, amount: 0.05, included_in_price: included_in_price, zone: zone) }
let!(:rate) { create(:tax_rate, tax_categories: [tax_category], amount: 0.05, included_in_price: included_in_price, zone: zone) }
let(:included_in_price) { false }
let(:default_tax) { false }
subject(:calculator) { Spree::Calculator::DefaultTax.new(calculable: rate ) }
Expand Down
2 changes: 1 addition & 1 deletion core/spec/models/spree/order/checkout_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def assert_state_changed(order, from, to)

it "recalculates tax and updates totals" do
zone = create(:zone, countries: [order.tax_address.country])
create(:tax_rate, tax_category: line_item.tax_category, amount: 0.05, zone: zone)
create(:tax_rate, tax_categories: [line_item.tax_category], amount: 0.05, zone: zone)
order.next!
expect(order).to have_attributes(
adjustment_total: 0.5,
Expand Down
2 changes: 1 addition & 1 deletion core/spec/models/spree/order_capturing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

let!(:product) { create(:product, price: 10.00) }
let!(:variant) do
create(:variant, price: 10, product: product, track_inventory: false, tax_category: tax_rate.tax_category)
create(:variant, price: 10, product: product, track_inventory: false, tax_category: tax_rate.tax_categories.first)
end
let!(:shipping_method) { create(:free_shipping_method) }
let(:tax_rate) { create(:tax_rate, amount: 0.1, zone: create(:global_zone, name: "Some Tax Zone")) }
Expand Down
2 changes: 1 addition & 1 deletion core/spec/models/spree/order_contents_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
describe 'tax calculations' do
let!(:zone) { create(:global_zone) }
let!(:tax_rate) do
create(:tax_rate, zone: zone, tax_category: variant.tax_category)
create(:tax_rate, zone: zone, tax_categories: [variant.tax_category])
end

context 'when the order has a taxable address' do
Expand Down
2 changes: 1 addition & 1 deletion core/spec/models/spree/order_updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def create_adjustment(label, amount)
describe 'tax recalculation' do
let!(:ship_address) { create(:address) }
let!(:tax_zone) { create(:global_zone) } # will include the above address
let!(:tax_rate) { create(:tax_rate, zone: tax_zone, tax_category: tax_category) }
let!(:tax_rate) { create(:tax_rate, zone: tax_zone, tax_categories: [tax_category]) }

let(:order) do
create(
Expand Down
2 changes: 1 addition & 1 deletion core/spec/models/spree/price_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
describe 'net_amount' do
let(:country) { create(:country, iso: "DE") }
let(:zone) { create(:zone, countries: [country]) }
let!(:tax_rate) { create(:tax_rate, included_in_price: true, zone: zone, tax_category: variant.tax_category) }
let!(:tax_rate) { create(:tax_rate, included_in_price: true, zone: zone, tax_categories: [variant.tax_category]) }

let(:variant) { create(:product).master }

Expand Down
2 changes: 1 addition & 1 deletion core/spec/models/spree/promotion_handler/coupon_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def expect_adjustment_creation(adjustable:, promotion:, promotion_code:nil)
let(:order) { create(:order, store: store) }
let(:tax_category) { create(:tax_category, name: "Taxable Foo") }
let(:zone) { create(:zone, :with_country) }
let!(:tax_rate) { create(:tax_rate, amount: 0.1, tax_category: tax_category, zone: zone )}
let!(:tax_rate) { create(:tax_rate, amount: 0.1, tax_categories: [tax_category], zone: zone ) }

before(:each) do
expect(order).to receive(:tax_address).at_least(:once).and_return(Spree::Tax::TaxLocation.new(country: zone.countries.first))
Expand Down
4 changes: 2 additions & 2 deletions core/spec/models/spree/shipment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@

let!(:ship_address) { create(:address) }
let!(:tax_zone) { create(:global_zone) } # will include the above address
let!(:tax_rate) { create(:tax_rate, amount: 0.1, zone: tax_zone, tax_category: tax_category) }
let!(:tax_rate) { create(:tax_rate, amount: 0.1, zone: tax_zone, tax_categories: [tax_category]) }
let(:tax_category) { create(:tax_category) }
let(:variant) { create(:variant, tax_category: tax_category) }

Expand Down Expand Up @@ -548,7 +548,7 @@
context "changes shipping rate via general update" do
let!(:ship_address) { create(:address) }
let!(:tax_zone) { create(:global_zone) } # will include the above address
let!(:tax_rate) { create(:tax_rate, amount: 0.10, zone: tax_zone, tax_category: tax_category) }
let!(:tax_rate) { create(:tax_rate, amount: 0.10, zone: tax_zone, tax_categories: [tax_category]) }
let(:tax_category) { create(:tax_category) }

let(:order) do
Expand Down
10 changes: 5 additions & 5 deletions core/spec/models/spree/shipping_rate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
included_in_price: true,
name: "VAT",
zone: default_zone,
tax_category: tax_category
tax_categories: [tax_category]
end

let(:order_address) { address }
Expand Down Expand Up @@ -64,7 +64,7 @@
included_in_price: true,
name: "VAT",
zone: default_zone,
tax_category: tax_category
tax_categories: [tax_category]
end

let(:order_address) { foreign_address }
Expand Down Expand Up @@ -96,7 +96,7 @@
included_in_price: false,
name: "Sales Tax",
zone: default_zone,
tax_category: tax_category
tax_categories: [tax_category]
end

let(:order_address) { address }
Expand Down Expand Up @@ -126,15 +126,15 @@
included_in_price: false,
name: "Sales Tax",
zone: default_zone,
tax_category: tax_category
tax_categories: [tax_category]
end

let!(:other_tax_rate) do
create :tax_rate,
included_in_price: false,
name: "Other Sales Tax",
zone: default_zone,
tax_category: tax_category,
tax_categories: [tax_category],
amount: 0.05
end

Expand Down
2 changes: 1 addition & 1 deletion core/spec/models/spree/stock/estimator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ module Stock
let!(:tax_rate) { create(:tax_rate, zone: zone) }

before do
shipping_method.update!(tax_category: tax_rate.tax_category)
shipping_method.update!(tax_category: tax_rate.tax_categories.first)
end

it "links the shipping rate and the tax rate" do
Expand Down
16 changes: 11 additions & 5 deletions core/spec/models/spree/tax/item_adjuster_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,22 @@ def tax_adjustments
end

context 'when there are matching rates for the zone' do
context 'and all rates have the same tax category as the item' do
context "and there matching tax rates for the item" do
let(:item_tax_category) { build(:tax_category) }
let(:item) { build_stubbed :line_item, order: order, tax_category: item_tax_category }
let(:item_tax_category) { build_stubbed(:tax_category) }
let(:rate_1) { create :tax_rate, tax_category: item_tax_category }
let(:rate_1) { create :tax_rate, tax_categories: [item_tax_category] }
let(:rate_2) { create :tax_rate }
let(:rates_for_order_zone) { [rate_1, rate_2] }
let(:rate_3) { create :tax_rate, tax_categories: [item_tax_category, build(:tax_category)] }
let(:rates_for_order_zone) { [rate_1, rate_2, rate_3] }

it 'creates an adjustment for every matching rate' do
adjuster.adjust!
expect(tax_adjustments.length).to eq(1)
expect(tax_adjustments.length).to eq(2)
end

it 'creates adjustments only for matching rates' do
adjuster.adjust!
expect(tax_adjustments.map(&:source)).to match_array([rate_1, rate_3])
end
end
end
Expand Down
13 changes: 10 additions & 3 deletions core/spec/models/spree/tax/shipping_rate_taxer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,19 @@
let(:shipment) { create :shipment, order: order }
let!(:shipping_method) { create :shipping_method, tax_category: tax_category, zones: [zone] }
let(:zone) { create :zone, countries: [ship_address.country] }
let!(:tax_rate_one) { create :tax_rate, tax_category: tax_category, zone: zone, amount: 0.1 }
let!(:tax_rate_two) { create :tax_rate, tax_category: tax_category, zone: zone, amount: 0.2 }
let!(:tax_rate_one) { create :tax_rate, tax_categories: [tax_category], zone: zone, amount: 0.1 }
let!(:tax_rate_two) do
create(
:tax_rate,
tax_categories: [create(:tax_category), tax_category],
zone: zone,
amount: 0.2
)
end
let!(:non_applicable_rate) { create :tax_rate, zone: zone }
let(:shipping_rate) { create :shipping_rate, cost: 10, shipping_method: shipping_method }

it 'builds a shipping rate tax for every tax rate' do
it 'builds a shipping rate tax for every matching tax rate' do
expect(subject.taxes.length).to eq(2)
expect(subject.taxes.map(&:tax_rate)).to include(tax_rate_one)
expect(subject.taxes.map(&:tax_rate)).to include(tax_rate_two)
Expand Down
51 changes: 43 additions & 8 deletions core/spec/models/spree/tax/taxation_integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,24 @@
tax_category: normal_category,
shipping_category: normal_shipping_category
end
let(:fruit_product) do
create :product,
price: 5,
name: "Food",
tax_category: fruit_category,
shipping_category: normal_shipping_category
end

let(:book) { book_product.master }
let(:download) { download_product.master }
let(:sweater) { sweater_product.master }
let(:fruit) { fruit_product.master }

let(:books_category) { create :tax_category, name: "Books" }
let(:normal_category) { create :tax_category, name: "Normal" }
let(:digital_category) { create :tax_category, name: "Digital Goods" }
let(:fruit_category) { create :tax_category, name: "Fruit Product" }
let(:milk_category) { create :tax_category, name: "Milk Product" }

let(:books_shipping_category) { create :shipping_category, name: "Book Shipping" }
let(:normal_shipping_category) { create :shipping_category, name: "Normal Shipping" }
Expand All @@ -55,7 +65,7 @@
name: "German reduced VAT",
included_in_price: true,
amount: 0.07,
tax_category: books_category,
tax_categories: [books_category],
zone: eu_zone
)
end
Expand All @@ -65,7 +75,7 @@
name: "German VAT",
included_in_price: true,
amount: 0.19,
tax_category: normal_category,
tax_categories: [normal_category],
zone: eu_zone
)
end
Expand All @@ -75,7 +85,17 @@
name: "German VAT",
included_in_price: true,
amount: 0.19,
tax_category: digital_category,
tax_categories: [digital_category],
zone: germany_zone
)
end
let!(:german_food_vat) do
create(
:tax_rate,
name: "German Food VAT",
included_in_price: true,
amount: 0.09,
tax_categories: [fruit_category, milk_category],
zone: germany_zone
)
end
Expand All @@ -85,7 +105,7 @@
name: "Romanian VAT",
included_in_price: true,
amount: 0.24,
tax_category: digital_category,
tax_categories: [digital_category],
zone: romania_zone
)
end
Expand Down Expand Up @@ -222,6 +242,22 @@
expect(shipping_rate.display_price).to eq("$2.00 (incl. $0.32 German VAT)")
end
end

context 'an order containg a fruit' do
let(:variant) { fruit }

it 'still has the original price' do
expect(line_item.price).to eq(5)
end

it 'has one tax adjustment' do
expect(line_item.adjustments.tax.count).to eq(1)
end

it 'has 0.45 of included tax' do
expect(line_item.included_tax_total).to eq(0.41)
end
end
end

context 'to romania' do
Expand Down Expand Up @@ -345,7 +381,6 @@
end
end
end

# Technically, this can't be the case yet as the order won't pass the shipment stage,
# but the taxation code shouldn't implicitly depend on the shipping code.
context 'to an address that does not have a zone associated' do
Expand Down Expand Up @@ -528,7 +563,7 @@
create(
:tax_rate,
name: "New York Sales Tax",
tax_category: books_category,
tax_categories: [books_category],
zone: new_york_zone,
included_in_price: false,
amount: 0.05
Expand All @@ -539,7 +574,7 @@
create(
:tax_rate,
name: "Federal Sales Tax",
tax_category: books_category,
tax_categories: [books_category],
zone: united_states_zone,
included_in_price: false,
amount: 0.10
Expand All @@ -550,7 +585,7 @@
create(
:tax_rate,
name: "Federal Sales Tax",
tax_category: digital_category,
tax_categories: [digital_category],
zone: united_states_zone,
included_in_price: false,
amount: 0.20
Expand Down
8 changes: 4 additions & 4 deletions core/spec/models/spree/variant/vat_price_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
context "with Germany as default admin country" do
let(:germany) { create(:country, iso: "DE") }
let(:germany_zone) { create(:zone, countries: [germany]) }
let!(:german_vat) { create(:tax_rate, included_in_price: true, amount: 0.19, zone: germany_zone, tax_category: tax_category) }
let!(:german_vat) { create(:tax_rate, included_in_price: true, amount: 0.19, zone: germany_zone, tax_categories: [tax_category]) }
let(:france) { create(:country, iso: "FR") }
let(:france_zone) { create(:zone, countries: [france]) }
let!(:french_vat) { create(:tax_rate, included_in_price: true, amount: 0.20, zone: france_zone, tax_category: tax_category) }
let!(:french_vat) { create(:tax_rate, included_in_price: true, amount: 0.20, zone: france_zone, tax_categories: [tax_category]) }

before do
Spree::Config.admin_vat_country_iso = "DE"
Expand Down Expand Up @@ -45,10 +45,10 @@
context "with no default admin country" do
let(:germany) { create(:country, iso: "DE") }
let(:germany_zone) { create(:zone, countries: [germany]) }
let!(:german_vat) { create(:tax_rate, included_in_price: true, amount: 0.19, zone: germany_zone, tax_category: tax_category) }
let!(:german_vat) { create(:tax_rate, included_in_price: true, amount: 0.19, zone: germany_zone, tax_categories: [tax_category]) }
let(:france) { create(:country, iso: "FR") }
let(:france_zone) { create(:zone, countries: [france]) }
let!(:french_vat) { create(:tax_rate, included_in_price: true, amount: 0.20, zone: france_zone, tax_category: tax_category) }
let!(:french_vat) { create(:tax_rate, included_in_price: true, amount: 0.20, zone: france_zone, tax_categories: [tax_category]) }

it "builds a correct price including VAT for all VAT countries" do
subject
Expand Down
4 changes: 2 additions & 2 deletions core/spec/models/spree/variant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@

let(:tax_category) { create(:tax_category) }

let!(:high_vat) { create(:tax_rate, included_in_price: true, amount: 0.25, zone: high_vat_zone, tax_category: tax_category) }
let!(:low_vat) { create(:tax_rate, included_in_price: true, amount: 0.15, zone: low_vat_zone, tax_category: tax_category) }
let!(:high_vat) { create(:tax_rate, included_in_price: true, amount: 0.25, zone: high_vat_zone, tax_categories: [tax_category]) }
let!(:low_vat) { create(:tax_rate, included_in_price: true, amount: 0.15, zone: low_vat_zone, tax_categories: [tax_category]) }

let(:product) { build(:product, tax_category: tax_category) }

Expand Down

0 comments on commit d8bb9e9

Please sign in to comment.