require File.dirname(__FILE__) + "/../../../spec_helper" # # Tests for shop order tags module # describe Shop::Tags::Cart do dataset :pages, :tags, :shop_config, :shop_orders, :shop_payments it 'should describe these tags' do Shop::Tags::Cart.tags.sort.should == [ 'shop:cart', 'shop:cart:forget', 'shop:cart:if_cart', 'shop:cart:unless_cart', 'shop:cart:payment', 'shop:cart:payment:if_paid', 'shop:cart:payment:unless_paid', 'shop:cart:payment:date', 'shop:cart:id', 'shop:cart:status', 'shop:cart:quantity', 'shop:cart:weight', 'shop:cart:notes', 'shop:cart:price'].sort end context 'cart tags' do before :all do @page = pages(:home) end before :each do @order = shop_orders(:several_items) mock_valid_tag_for_helper end describe '' do context 'success' do it 'should render' do mock(Shop::Tags::Helpers).current_order(anything) { @order } tag = %{success} expected = %{success} @page.should render(tag).as(expected) @tag.locals.page.request.session[:shop_order].should be_nil end end context 'failure' do it 'should render' do tag = %{success} expected = %{success} @page.should render(tag).as(expected) end end end describe '' do it 'should remove the cart from the session' do pending 'dont know how to test this' @tag.locals.page.request.session[:shop_order] = @order tag = %{} expected = %{} @page.should render(tag).as(expected) end end describe '' do context 'success' do it 'should render' do mock(Shop::Tags::Helpers).current_order(anything) { @order } tag = %{success} expected = %{success} @page.should render(tag).as(expected) end end context 'failure' do it 'should render' do mock(Shop::Tags::Helpers).current_order(anything) { nil } tag = %{failure} expected = %{} @page.should render(tag).as(expected) end end end describe '' do context 'success' do it 'should render' do mock(Shop::Tags::Helpers).current_order(anything) { nil } tag = %{success} expected = %{success} @page.should render(tag).as(expected) end end context 'failure' do it 'should render' do mock(Shop::Tags::Helpers).current_order(anything) { @order } tag = %{failure} expected = %{} @page.should render(tag).as(expected) end end end context 'payment' do before :each do mock(Shop::Tags::Helpers).current_order(anything) { @order } @order.status = 'paid' end describe '' do context 'payment exists' do it 'should expand' do tag = %{success} expected = %{success} @page.should render(tag).as(expected) end end context 'payment doesnt exist' do it 'should expand' do stub(@order).paid? { false } tag = %{success} expected = %{success} @page.should render(tag).as(expected) end end end describe '' do context 'payment exists' do it 'should expand' do tag = %{success} expected = %{success} @page.should render(tag).as(expected) end end context 'payment doesnt exist' do it 'should expand' do stub(@order).paid? { false } tag = %{failure} expected = %{} @page.should render(tag).as(expected) end end end describe '' do context 'payment exists' do it 'should expand' do stub(@order).paid? { false } tag = %{success} expected = %{success} @page.should render(tag).as(expected) end end context 'payment doesnt exist' do it 'should expand' do tag = %{failure} expected = %{} @page.should render(tag).as(expected) end end end describe '' do it 'should return the created_at date of the payment' do tag = %{} expected = @order.payment.created_at.strftime(Radiant::Config['shop.date_format']) @page.should render(tag).as(expected) end end end describe 'simple attributes' do before :each do mock(Shop::Tags::Helpers).current_order(anything) { @order } end it 'should render ' do tag = %{} expected = @order.id.to_s @page.should render(tag).as(expected) end it 'should render ' do tag = %{} expected = @order.status @page.should render(tag).as(expected) end it 'should render ' do stub(@shop_order).quantity { 1 } tag = %{} expected = @order.quantity.to_s @page.should render(tag).as(expected) end it 'should render ' do tag = %{} expected = @order.weight.to_s @page.should render(tag).as(expected) end it 'should render ' do tag = %{} expected = @order.notes.to_s @page.should render(tag).as(expected) end end describe '' do before :each do mock(Shop::Tags::Helpers).current_order(anything) { @order } stub(@order).price { 1234.34567890 } end it 'should render a standard price' do tag = %{} expected = %{$1,234.35} @page.should render(tag).as(expected) end it 'should render a high precision price' do tag = %{} expected = %{$1,234.34567890} @page.should render(tag).as(expected) end it 'should render a custom format' do tag = %{} expected = %{%1+234-35} @page.should render(tag).as(expected) end end end end