require 'spec/spec_helper' describe Shop::Tags::ProductVariant do dataset :pages, :shop_product_variants, :shop_products it 'should describe these tags' do Shop::Tags::ProductVariant.tags.sort.should == [ 'shop:product:variants', 'shop:product:variants:each', 'shop:product:variants:if_variants', 'shop:product:variants:unless_variants', 'shop:product:variant', 'shop:product:variant:id', 'shop:product:variant:name', 'shop:product:variant:sku', 'shop:product:variant:price'].sort end before :all do @page = pages(:home) end context 'tags' do before :each do @product = shop_products(:crusty_bread) @variant = shop_product_variants(:mouldy_crusty_bread) stub(Shop::Tags::Helpers).current_product(anything) { @product } end describe '' do context 'variants exist' do it 'should render' do tag = %{success} exp = %{success} @page.should render(tag).as(exp) end end context 'variants do not exist' do it 'should render' do @product.variants = [] 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 not render' do mock(Shop::Tags::Helpers).current_product_variants(anything) { [] } tag = %{failure} exp = %{} @page.should render(tag).as(exp) end end end describe '' do context 'success' do it 'should render' do mock(Shop::Tags::Helpers).current_product_variants(anything) { [] } tag = %{success} exp = %{success} @page.should render(tag).as(exp) end end context 'failure' do it 'should not render' do tag = %{failure} exp = %{} @page.should render(tag).as(exp) end end end describe '' do context 'success' do it 'should not render' do tag = %{} exp = @product.variants.map{ |p| p.product.id }.join('') @page.should render(tag).as(exp) end end context 'failure' do it 'should not render' do mock(Shop::Tags::Helpers).current_product_variants(anything) { [] } tag = %{failure} exp = %{} @page.should render(tag).as(exp) end end end describe '' do context 'variant exists in the context' do it 'should render' do mock(Shop::Tags::Helpers).current_product_variant(anything) { @variant } tag = %{success} exp = %{success} @page.should render(tag).as(exp) end end context 'product does not exist in the context' do it 'should not render' do mock(Shop::Tags::Helpers).current_product_variant(anything) { nil } tag = %{failure} exp = %{} @page.should render(tag).as(exp) end end end context '#attributes' do before :each do mock(Shop::Tags::Helpers).current_product_variant(anything) { @variant } end describe '' do it 'should render the product id' do tag = %{} exp = @variant.id.to_s @page.should render(tag).as(exp) end end describe '' do it 'should render the product name' do tag = %{} exp = @variant.name @page.should render(tag).as(exp) end end describe '' do it 'should render the product sku' do tag = %{} exp = @variant.sku @page.should render(tag).as(exp) end end describe '' do it 'should render a standard price' do tag = %{} exp = Shop::Tags::Helpers.currency(@variant.price,{}) @page.should render(tag).as(exp) end end end end end