require File.dirname(__FILE__) + "/../../../spec_helper" # # Tests for shop address tags # describe Shop::Tags::Tax do dataset :pages, :shop_line_items it 'should describe these tags' do Shop::Tags::Tax.tags.sort.should == [ 'shop:cart:tax', 'shop:cart:tax:if_tax', 'shop:cart:tax:unless_tax', 'shop:cart:tax:name', 'shop:cart:tax:percentage', 'shop:cart:tax:strategy', 'shop:cart:tax:cost', 'shop:cart:tax:if_inclusive', 'shop:cart:tax:if_exclusive' ].sort end context 'inside cart' do before :all do Radiant::Config['shop.tax_strategy'] = 'inclusive' Radiant::Config['shop.tax_name'] = 'gst' Radiant::Config['shop.tax_percentage'] = '10' @page = pages(:home) end before :each do @order = shop_orders(:several_items) mock(Shop::Tags::Helpers).current_order(anything) { @order } end describe '' do it 'should expand' do tag = %{success} exp = %{success} @page.should render(tag).as(exp) end end describe '' do context 'tax configured correctly' do context 'inclusive' do before :each do Radiant::Config['shop.tax_strategy'] = 'inclusive' end it 'should expand' do tag = %{success} exp = %{success} @page.should render(tag).as(exp) end end context 'exclusive' do before :each do Radiant::Config['shop.tax_strategy'] = 'exclusive' end it 'should expand' do tag = %{success} exp = %{success} @page.should render(tag).as(exp) end end end context 'tax not configured correctly' do before :each do Radiant::Config['shop.tax_strategy'] = 'failure' end it 'should not expand' do tag = %{failure} exp = %{} @page.should render(tag).as(exp) end end end describe '' do context 'tax configured correctly' do context 'inclusive' do before :each do Radiant::Config['shop.tax_strategy'] = 'inclusive' end it 'should not expand' do tag = %{failure} exp = %{} @page.should render(tag).as(exp) end end context 'exclusive' do before :each do Radiant::Config['shop.tax_strategy'] = 'exclusive' end it 'should not expand' do tag = %{failure} exp = %{} @page.should render(tag).as(exp) end end end context 'tax not configured correctly' do before :each do Radiant::Config['shop.tax_strategy'] = 'failure' end it 'should expand' do tag = %{success} exp = %{success} @page.should render(tag).as(exp) end end end describe '' do it 'should return the tax strategy' do tag = %{} exp = Radiant::Config['shop.tax_strategy'] @page.should render(tag).as(exp) end end describe '' do it 'should return the tax name' do tag = %{} exp = Radiant::Config['shop.tax_name'] @page.should render(tag).as(exp) end end describe '' do it 'should return the tax percentage' do tag = %{} exp = Radiant::Config['shop.tax_percentage'] @page.should render(tag).as(exp) end end describe '' do it 'should return the cost of tax on the cart' do tag = %{} exp = ::Shop::Tags::Helpers.currency(@order.tax) @page.should render(tag).as(exp) end end describe '' do context 'is inclusive' do it 'should expand' do Radiant::Config['shop.tax_strategy'] = 'inclusive' tag = %{success} exp = %{success} @page.should render(tag).as(exp) end end context 'not inclusive' do it 'should not expand' do Radiant::Config['shop.tax_strategy'] = 'exclusive' tag = %{failure} exp = %{} @page.should render(tag).as(exp) end end end describe '' do context 'is exclusive' do it 'should expand' do Radiant::Config['shop.tax_strategy'] = 'exclusive' tag = %{success} exp = %{success} @page.should render(tag).as(exp) end end context 'not exclusive' do it 'should not expand' do Radiant::Config['shop.tax_strategy'] = 'inclusive' tag = %{failure} exp = %{} @page.should render(tag).as(exp) end end end end end