require 'spec/spec_helper' require 'spec/helpers/nested_tag_helper' # # Test for Shop Line Item Tags # describe Shop::Tags::Item do dataset :pages, :shop_orders, :shop_line_items it 'should describe these tags' do Shop::Tags::Item.tags.sort.should == [ 'shop:cart:items', 'shop:cart:items:if_items', 'shop:cart:items:unless_items', 'shop:cart:items:each', 'shop:cart:item', 'shop:cart:item:id', 'shop:cart:item:quantity', 'shop:cart:item:name', 'shop:cart:item:sku', 'shop:cart:item:link', 'shop:cart:item:price', 'shop:cart:item:value', 'shop:cart:item:discounted', 'shop:cart:item:if_discounted', 'shop:cart:item:unless_discounted'].sort end context 'within a cart' do before :all do @page = pages(:home) end context 'order does not exist' do describe '' do it 'should not render' do tag = %{failure} exp = %{} @page.should render(tag).as(exp) end end end context 'order exists' do before :each do @order = shop_orders(:several_items) mock(Shop::Tags::Helpers).current_order(anything) { @order } end describe '' do context 'items exist in cart' do context 'no parameters sent to tag' do it 'should render' do tag = %{success} exp = %{success} @page.should render(tag).as(exp) end end context 'parameters sent to tag' do it 'should render' do tag = %{success} exp = %{success} @page.should render(tag).as(exp) end end end context 'items dont exist in cart' do it 'should render' do tag = %{success} exp = %{success} @page.should render(tag).as(exp) end end end describe '' do context 'success' do it 'should render' do tag = %{success} exp = %{success} @page.should render(tag).as(exp) end end context 'failure' do it 'should render' do stub(@order).line_items { [] } tag = %{failure} exp = %{} @page.should render(tag).as(exp) end end end describe '' do context 'success' do it 'should render' do stub(@order).line_items { [] } tag = %{success} exp = %{success} @page.should render(tag).as(exp) end end context 'failure' do it 'should render' do tag = %{failure} exp = %{} @page.should render(tag).as(exp) end end end describe '' do context 'success' do it 'should render' do tag = %{.a.} exp = @order.line_items.map{ '.a.' }.join('') @page.should render(tag).as(exp) end it 'should assign the local item' do tag = %{} exp = @order.line_items.map{ |i| i.id }.join('') @page.should render(tag).as(exp) end it 'should assign the local item' do tag = %{} exp = @order.line_items.map{ |i| i.item.name }.join('') @page.should render(tag).as(exp) end end context 'failure' do it 'should not render' do stub(@order).line_items { [] } tag = %{} exp = %{} @page.should render(tag).as(exp) end end end end context 'a single item' do before :each do @order = shop_orders(:several_items) mock(Shop::Tags::Helpers).current_order(anything) { @order } @line_item = @order.line_items.first end describe '' do context 'success' do it 'should render' do mock(Shop::Tags::Helpers).current_line_item(anything) { @line_item } tag = %{success} exp = %{success} @page.should render(tag).as(exp) end end context 'failure' do it 'should not render' do mock(Shop::Tags::Helpers).current_line_item(anything) { nil } tag = %{failure} exp = %{} @page.should render(tag).as(exp) end end describe 'simple attributes' do before :each do mock(Shop::Tags::Helpers).current_line_item(anything) { @line_item } end it 'should render ' do tag = %{} exp = @line_item.id.to_s @page.should render(tag).as(exp) end it 'should render ' do tag = %{} exp = @line_item.quantity.to_s @page.should render(tag).as(exp) end end describe 'item attributes' do before :each do mock(Shop::Tags::Helpers).current_line_item(anything) { @line_item } end it 'should render ' do tag = %{} exp = @line_item.item.name @page.should render(tag).as(exp) end it 'should render ' do tag = %{} exp = @line_item.item.sku @page.should render(tag).as(exp) end end describe '' do before :each do mock(Shop::Tags::Helpers).current_line_item(anything) { @line_item } end context 'standalone' do it 'should render an anchor element' do tag = %{} exp = %{#{@line_item.item.name}} pages(:home).should render(tag).as(exp) end it 'should assign attributes' do tag = %{} exp = %{#{@line_item.item.name}} pages(:home).should render(tag).as(exp) end end context 'wrapped' do it 'should render an anchor element' do tag = %{title} exp = %{title} pages(:home).should render(tag).as(exp) end end end describe '' do before :each do mock(Shop::Tags::Helpers).current_line_item(anything) { @line_item } stub(@line_item).price { 1234.34567890 } end it 'should render a standard price' do tag = %{} exp = %{$1,234.35} @page.should render(tag).as(exp) end it 'should render a high precision price' do tag = %{} exp = %{$1,234.34567890} @page.should render(tag).as(exp) end it 'should render a custom format' do tag = %{} exp = %{%1+234-35} @page.should render(tag).as(exp) end end end end end end