require File.dirname(__FILE__) + "/../../../spec_helper" describe Shop::Tags::Category do dataset :pages, :shop_categories, :shop_products it 'should describe these tags' do Shop::Tags::Category.tags.sort.should == [ 'shop:categories', 'shop:categories:each', 'shop:categories:if_categories', 'shop:categories:unless_categories', 'shop:category', 'shop:category:description', 'shop:category:handle', 'shop:category:id', 'shop:category:if_current', 'shop:category:link', 'shop:category:name', 'shop:category:slug'].sort end before :each do @page = pages(:home) end before(:each) do @category = shop_categories(:bread) end describe '' do context 'categories exist' do it 'should render' do mock(Shop::Tags::Helpers).current_categories(anything) { [@category] } tag = %{success} exp = %{success} @page.should render(tag).as(exp) end end context 'categories dont exist' do it 'should render' do mock(Shop::Tags::Helpers).current_categories(anything) { [] } 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_categories(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_categories(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 before :each do mock(Shop::Tags::Helpers).current_category(anything) { @category } end context 'this categories page' do it 'should expand' do tag = %{success} exp = %{success} @category.page.should render(tag).as(exp) end end context 'categories product page' do it 'should expand' do tag = %{success} exp = %{success} @category.products.first.page.should render(tag).as(exp) end end context 'failure' do it 'should not expand' do tag = %{failure} exp = %{} @page.should render(tag).as(exp) end end end describe 'simple attributes' do before :each do mock(Shop::Tags::Helpers).current_category(anything) { @category } end it 'should render ' do tag = %{} exp = @category.id.to_s @page.should render(tag).as(exp) end it 'should render ' do tag = %{} exp = @category.name @page.should render(tag).as(exp) end it 'should render ' do tag = %{} exp = @category.handle @page.should render(tag).as(exp) end it 'should render ' do tag = %{} exp = @category.slug @page.should render(tag).as(exp) end describe '' do it 'should render a textile filtered result' do tag = %{} exp = TextileFilter.filter(@category.description) @page.should render(tag).as(exp) end end end describe '' do before :each do mock(Shop::Tags::Helpers).current_category(anything) { @category } end context 'standalone' do it 'should render an anchor element' do tag = %{} exp = %{#{@category.name}} @page.should render(tag).as(exp) end it 'should assign attributes' do tag = %{} exp = %{#{@category.name}} @page.should render(tag).as(exp) end end context 'wrapped' do it 'should render an anchor element' do tag = %{title} exp = %{title} @page.should render(tag).as(exp) end end end end