require 'spec/spec_helper' require 'spec/helpers/nested_tag_helper' # # Test for Shop Line Item Tags # describe Shop::Tags::Item do dataset :pages it 'should describe these tags' do Shop::Tags::Item.tags.sort.should == [ 'shop:cart:if_items', 'shop:cart:unless_items', 'shop:cart:items', 'shop:cart:items:each', 'shop:cart:item', 'shop:cart:item:id', 'shop:cart:item:quantity', 'shop:cart:item:name', 'shop:cart:item:link', 'shop:cart:item:price', 'shop:cart:item:weight', 'shop:cart:item:remove'].sort end before :all do @page = pages(:home) end before :each do order = Object.new stub(order).id { 1 } @shop_order = order item = Object.new stub(item).id { 1 } @shop_line_item = item product = Object.new stub(product).id { 1 } @shop_product = product stub(@shop_line_item).item { @shop_product } stub(@shop_line_item).order { @shop_order } @shop_line_items = [ @shop_line_item, @shop_line_item, @shop_line_item ] stub(@shop_order).line_items { @shop_line_items } end context 'within a cart' do before :each do mock(Shop::Tags::Helpers).current_order(anything) { @shop_order } end context 'group of items' do describe '' do context 'success' do it 'should render' do tag = %{success} expected = %{success} @page.should render(tag).as(expected) end end context 'failure' do it 'should render' do stub(@shop_order).line_items { [] } tag = %{failure} expected = %{} @page.should render(tag).as(expected) end end end describe '' do context 'success' do it 'should render' do stub(@shop_order).line_items { [] } tag = %{success} expected = %{success} @page.should render(tag).as(expected) end end context 'failure' do it 'should render' do tag = %{failure} expected = %{} @page.should render(tag).as(expected) end end end describe '' do context 'items exist' do it 'should render' do tag = %{success} expected = %{success} @page.should render(tag).as(expected) end end context 'items dont exist' do it 'should render' do tag = %{success} expected = %{success} @page.should render(tag).as(expected) end end end describe '.a.} expected = %{.a..a..a.} @page.should render(tag).as(expected) end it 'should assign the local item' do tag = %{} expected = %{111} @page.should render(tag).as(expected) end it 'should assign the local product' do tag = %{} expected = %{111} @page.should render(tag).as(expected) end end context 'failure' do it 'should not render' do stub(@shop_order).line_items { [] } tag = %{} expected = %{} @page.should render(tag).as(expected) end end end end context 'a single item' do describe '' do context 'success' do it 'should render' do mock(Shop::Tags::Helpers).current_line_item(anything) { @shop_line_item } tag = %{success} expected = %{success} @page.should render(tag).as(expected) end end context 'failure' do it 'should not render' do mock(Shop::Tags::Helpers).current_line_item(anything) { nil } tag = %{failure} expected = %{} @page.should render(tag).as(expected) end end describe 'simple attributes' do before :each do mock(Shop::Tags::Helpers).current_line_item(anything) { @shop_line_item } end it 'should render ' do stub(@shop_line_item).id { 1 } tag = %{} expected = %{1} @page.should render(tag).as(expected) end it 'should render ' do stub(@shop_line_item).quantity { 1 } tag = %{} expected = %{1} @page.should render(tag).as(expected) end end describe 'item attributes' do before :each do mock(Shop::Tags::Helpers).current_line_item(anything) { @shop_line_item } end it 'should render ' do stub(@shop_line_item).item.stub!.name { 'name' } tag = %{} expected = %{name} @page.should render(tag).as(expected) end it 'should render ' do stub(@shop_line_item).item.stub!.weight { 100 } tag = %{} expected = %{100} @page.should render(tag).as(expected) end end describe '' do before :each do mock(Shop::Tags::Helpers).current_line_item(anything) { @shop_line_item } end context 'standalone' do before :each do item = Object.new stub(@shop_line_item).item { item } stub(item).slug { 'slug' } stub(item).name { 'name' } end it 'should render an anchor element' do tag = %{} expected = %{name} pages(:home).should render(tag).as(expected) end it 'should assign attributes' do tag = %{} expected = %{name} pages(:home).should render(tag).as(expected) end end context 'wrapped' do it 'should render an anchor element' do item = Object.new stub(@shop_line_item).item { item } stub(item).slug { 'slug' } tag = %{title} expected = %{title} pages(:home).should render(tag).as(expected) end end end describe '' do before :each do mock(Shop::Tags::Helpers).current_line_item(anything) { @shop_line_item } stub(@shop_line_item).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 describe '' do before :each do mock(Shop::Tags::Helpers).current_line_item(anything) { @shop_line_item } end context 'standalone' do it 'should render an anchor element' do tag = %{} expected = %{remove} pages(:home).should render(tag).as(expected) end it 'should assign attributes' do tag = %{} expected = %{remove} pages(:home).should render(tag).as(expected) end end context 'wrapped' do it 'should render an anchor element' do tag = %{get rid of me} expected = %{get rid of me} pages(:home).should render(tag).as(expected) end end end end end end end