diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 412c1dd..efb8eff 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -308,7 +308,7 @@ module ApplicationHelper def link_to_category(category) return _('Uncategorized product') unless category - link_to category.full_name, :controller => 'category', :action => 'view', :path => category.path.split('/') + link_to category.full_name, :controller => 'category', :action => 'view', :category_path => category.path.split('/') end def link_to_product(product) diff --git a/test/integration/categories_menu_test.rb b/test/integration/categories_menu_test.rb index a411e7c..ecd3067 100644 --- a/test/integration/categories_menu_test.rb +++ b/test/integration/categories_menu_test.rb @@ -13,4 +13,16 @@ class CategoriesMenuTest < ActionController::IntegrationTest end + should 'display link to sub-categories' do + Category.delete_all + cat1 = Category.create!(:name => 'Food', :environment => Environment.default) + cat2 = Category.create!(:name => 'Vegetables', :environment => Environment.default, :parent => cat1) + + get '/cat/food' + + # there must be a link to the subcategory + assert_tag :tag => 'a', :attributes => { :href => '/cat/food/vegetables' } + + end + end diff --git a/test/unit/application_helper_test.rb b/test/unit/application_helper_test.rb index 8dd0345..39dcfe1 100644 --- a/test/unit/application_helper_test.rb +++ b/test/unit/application_helper_test.rb @@ -55,6 +55,16 @@ class ApplicationHelperTest < Test::Unit::TestCase button('type', 'label', 'url', { :class => 'class1' }) end + should 'generate correct link to category' do + cat = mock + cat.expects(:path).returns('my-category/my-subcatagory') + cat.expects(:full_name).returns('category name') + + result = "/cat/my-category/my-subcatagory" + expects(:link_to).with('category name', :controller => 'category', :action => 'view', :category_path => ['my-category', 'my-subcatagory']).returns(result) + assert_same result, link_to_category(cat) + end + protected def content_tag(tag, content, options) -- libgit2 0.21.2