Skip to content

Instantly share code, notes, and snippets.

@jrochkind
Last active September 1, 2016 21:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrochkind/d8a5258539db692b68092657a42beafa to your computer and use it in GitHub Desktop.
Save jrochkind/d8a5258539db692b68092657a42beafa to your computer and use it in GitHub Desktop.
require 'spec_helper'
require 'carmen'
# Really more of a set of integration tests, we're proving that tax is actually
# calculated how we want on an order
describe ByZipTaxCalculator do
let!(:taxable_category) { create(:tax_category, name: "Sales and Use Tax", is_default: true) }
let!(:non_taxable_category) { create(:tax_category, name: "Non Taxable") }
before do
# load state seed data
create(:country,
iso_name: 'UNITED STATES',
name:'United States',
iso: 'US',
iso3: 'USA',
numcode: 840)
# Crazy hack to work around weird way spree default states loader works,
# to let us call it more than once. Would not be neccesary in solidus.
TOPLEVEL_BINDING.eval('self').instance_variable_set("@states", nil)
load Spree::Core::Engine.root + 'db/default/spree/states.rb'
end
let!(:calculator_seed_results) { ByZipTaxCalculator.create_seed_data! }
let(:zone) { calculator_seed_results.first }
let(:rate) { calculator_seed_results.second }
let(:taxable_state) { zone.zoneables.first }
describe "taxable state shipping address" do
let(:sales_tax_zipcode) { SalesTaxZipcode.create!(zipcode: '10000', combined_rate: 0.10.to_d, state: taxable_state.abbr) }
let(:taxable_zipcode) { sales_tax_zipcode.zipcode }
let(:zipcode_rate) { sales_tax_zipcode.combined_rate }
let(:taxable_address) { create(:address, state: taxable_state, zipcode: taxable_zipcode) }
describe "with shipping" do
let(:order) do
create(:order_with_line_items,
ship_total: 100,
ship_address: taxable_address
) do |order|
shipping_methods = order.shipments.collect(&:shipping_method).uniq
shipping_methods.each { |sm| sm.update(tax_category: taxable_category) }
order.update_totals
end
end
it "charges tax on shipping and item total" do
expect(order.tax_total).to eq round_currency((order.item_total + order.ship_total) * zipcode_rate)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment