From a50b650c656655a5977d860028e50acc361c54ca Mon Sep 17 00:00:00 2001 From: AntonioTerceiro Date: Tue, 1 Apr 2008 20:48:18 +0000 Subject: [PATCH] ActionItem155: fixing generation of links in the assets menu --- app/helpers/assets_helper.rb | 15 ++++++++------- test/integration/assets_menu_test.rb | 25 +++++++++++++++++++++++++ test/unit/assets_helper_test.rb | 20 ++++++++++++++++++-- 3 files changed, 51 insertions(+), 9 deletions(-) create mode 100644 test/integration/assets_menu_test.rb diff --git a/app/helpers/assets_helper.rb b/app/helpers/assets_helper.rb index 0a343fc..7534c51 100644 --- a/app/helpers/assets_helper.rb +++ b/app/helpers/assets_helper.rb @@ -1,14 +1,15 @@ module AssetsHelper def generate_assets_menu() - [ - [ { :controller => 'search', :action => 'assets', :asset => 'articles' }, "icon-menu-articles", _('Articles') ], - [ { :controller => 'search', :action => 'assets', :asset => 'people' }, "icon-menu-people", _('People') ], - [ { :controller => 'search', :action => 'assets', :asset => 'products' }, "icon-menu-product", _('Products') ], - [ { :controller => 'search', :action => 'assets', :asset => 'enterprises' }, "icon-menu-enterprise", _('Enterprises') ], - [ { :controller => 'search', :action => 'assets', :asset => 'communities' }, "icon-menu-community", _('Communities') ], - [ { :controller => 'search', :action => 'assets', :asset => 'comments'}, "icon-menu-comments", _('Comments') ], + options = { :controller => 'search', :action => 'assets', :category_path => (@category ? @category.explode_path : []) } + [ + [ options.merge(:asset => 'articles'), "icon-menu-articles", _('Articles') ], + [ options.merge(:asset => 'people'), "icon-menu-people", _('People') ], + [ options.merge(:asset => 'products'), "icon-menu-product", _('Products') ], + [ options.merge(:asset => 'enterprises'), "icon-menu-enterprise", _('Enterprises') ], + [ options.merge(:asset => 'communities'), "icon-menu-community", _('Communities') ], + [ options.merge(:asset => 'comments'), "icon-menu-comments", _('Comments') ], ].map do |target,css_class,name| content_tag('li', link_to(content_tag('span', '', :class => css_class) + name, target)) diff --git a/test/integration/assets_menu_test.rb b/test/integration/assets_menu_test.rb new file mode 100644 index 0000000..769ffc0 --- /dev/null +++ b/test/integration/assets_menu_test.rb @@ -0,0 +1,25 @@ +require "#{File.dirname(__FILE__)}/../test_helper" + +class AssetsMenuTest < ActionController::IntegrationTest + + def setup + parent = Category.create!(:name => "Parent Category", :environment => Environment.default, :display_color => 1) + @category = Category.create!(:name => "Category A", :environment => Environment.default, :parent => parent) + end + + should 'link to uncategorized assets at site root' do + get '/' + assert_tag :tag => 'a', :attributes => { :href => '/cat/parent-category/category-a' } + end + + should 'link to assets inside category root' do + get '/cat/parent-category/category-a' + assert_tag :tag => 'a', :attributes => { :href => '/assets/articles/parent-category/category-a' } + end + + should 'link to other assets in same category when' do + get '/assets/articles/parent-category/category-a' + assert_tag :tag => 'a', :attributes => { :href => '/assets/products/parent-category/category-a' } + end + +end diff --git a/test/unit/assets_helper_test.rb b/test/unit/assets_helper_test.rb index ce3c307..7a8d56b 100644 --- a/test/unit/assets_helper_test.rb +++ b/test/unit/assets_helper_test.rb @@ -12,14 +12,30 @@ class ApplicationHelperTest < Test::Unit::TestCase communities comments ].each do |asset| - expects(:link_to).with(anything, { :controller => 'search', :action => 'assets', :asset => asset}) + expects(:link_to).with(anything, { :controller => 'search', :action => 'assets', :asset => asset, :category_path => []}) end stubs(:_).returns('') stubs(:content_tag).returns('') generate_assets_menu - end + should 'generate link to assets with current category' do + %w[ articles + people + products + enterprises + communities + comments + ].each do |asset| + expects(:link_to).with(anything, { :controller => 'search', :action => 'assets', :asset => asset, :category_path => [ 'my-category' ]}) + end + + stubs(:_).returns('') + stubs(:content_tag).returns('') + @category = mock + @category.expects(:explode_path).returns(['my-category']).at_least_once + generate_assets_menu + end end -- libgit2 0.21.2