require 'spec/spec_helper' describe ShopPackages::Tags::Package do dataset :pages, :shop_packages it 'should describe these tags' do ShopPackages::Tags::Package.tags.sort.should == [ 'shop:packages', 'shop:packages:if_packages', 'shop:packages:unless_packages', 'shop:packages:each', 'shop:package', 'shop:package:id', 'shop:package:name', 'shop:package:sku', 'shop:package:description', 'shop:package:price', 'shop:package:value', 'shop:package:if_products', 'shop:package:unless_products', 'shop:package:products', 'shop:package:products:each', 'shop:package:product:quantity'].sort end before :all do @page = pages(:home) end before :each do @package = shop_packages(:all_bread) end context 'outside a package' do describe '' do context 'packages' do it 'should render' do tag = %{success} exp = %{success} @page.should render(tag).as(exp) end end context 'no packages' 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 mock(ShopPackages::Tags::Helpers).current_packages(anything) { [] } tag = %{failure} exp = %{} @page.should render(tag).as(exp) end end end describe '' do context 'success' do it 'should not render' do mock(ShopPackages::Tags::Helpers).current_packages(anything) { [] } tag = %{success} exp = %{success} @page.should render(tag).as(exp) end end context 'failure' do it 'should render' do mock(ShopPackages::Tags::Helpers).current_packages(anything) { ShopPackage.all } tag = %{failure} exp = %{} @page.should render(tag).as(exp) end end end describe '' do context 'success' do it 'should render' do mock(ShopPackages::Tags::Helpers).current_packages(anything) { ShopPackage.all } tag = %{.a.} exp = ShopPackage.all.map{ '.a.' }.join('') @page.should render(tag).as(exp) end end context 'failure' do it 'should not render' do mock(ShopPackages::Tags::Helpers).current_packages(anything) { [] } tag = %{failure} exp = %{} @page.should render(tag).as(exp) end end end describe '' do context 'success' do it 'should render' do mock(ShopPackages::Tags::Helpers).current_package(anything) { @package } tag = %{success} exp = %{success} @page.should render(tag).as(exp) end end context 'failure' do it 'should not render' do mock(ShopPackages::Tags::Helpers).current_package(anything) { nil } tag = %{failure} exp = %{} @page.should render(tag).as(exp) end end end end context 'within a package' do before :each do mock(ShopPackages::Tags::Helpers).current_package(anything) { @package } end context 'simple attributes' do describe '' do it 'should render the id' do tag = %{} exp = @package.id.to_s @page.should render(tag).as(exp) end end describe '' do it 'should render the name' do tag = %{} exp = @package.name.to_s @page.should render(tag).as(exp) end end describe '' do it 'should render the sku' do tag = %{} exp = @package.sku.to_s @page.should render(tag).as(exp) end end end describe '' do it 'should render a textile filtered result' do @package.description = '*bold*' tag = %{} exp = %{

bold

} @page.should render(tag).as(exp) end end context 'currency attributes' do before :each do Radiant::Config['shop.price_unit'] = '$' Radiant::Config['shop.price_precision'] = 2 Radiant::Config['shop.price_separator'] = '.' Radiant::Config['shop.price_delimiter'] = ',' end describe '' do before :each do @package.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 describe '' do before :each do stub(@package).value { 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 context 'products in a package' do before :each do mock(ShopPackages::Tags::Helpers).current_package(anything) { @package } 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 stub(@package).products { [] } tag = %{failure} exp = %{} @page.should render(tag).as(exp) end end end describe '' do context 'success' do it 'should render' do stub(@package).products { [] } 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 it 'should render' do tag = %{success} exp = %{success} @page.should render(tag).as(exp) end end describe '' do context 'success' do it 'should render' do tag = %{.a.} exp = @package.products.map{'.a.'}.join('') @page.should render(tag).as(exp) end end context 'failure' do it 'should not render' do stub(@package).packings { [] } tag = %{failure} exp = %{} @page.should render(tag).as(exp) end end end describe '' do it 'should render the quantity of the current packing' do tag = %{} exp = @package.packings.map{|p| p.quantity}.join('') @page.should render(tag).as(exp) end end end end