Commit a50b650c656655a5977d860028e50acc361c54ca
1 parent
96b71fb4
Exists in
master
and in
23 other branches
ActionItem155: fixing generation of links in the assets menu
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1629 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
3 changed files
with
51 additions
and
9 deletions
Show diff stats
app/helpers/assets_helper.rb
| 1 | module AssetsHelper | 1 | module AssetsHelper |
| 2 | 2 | ||
| 3 | def generate_assets_menu() | 3 | def generate_assets_menu() |
| 4 | - [ | ||
| 5 | 4 | ||
| 6 | - [ { :controller => 'search', :action => 'assets', :asset => 'articles' }, "icon-menu-articles", _('Articles') ], | ||
| 7 | - [ { :controller => 'search', :action => 'assets', :asset => 'people' }, "icon-menu-people", _('People') ], | ||
| 8 | - [ { :controller => 'search', :action => 'assets', :asset => 'products' }, "icon-menu-product", _('Products') ], | ||
| 9 | - [ { :controller => 'search', :action => 'assets', :asset => 'enterprises' }, "icon-menu-enterprise", _('Enterprises') ], | ||
| 10 | - [ { :controller => 'search', :action => 'assets', :asset => 'communities' }, "icon-menu-community", _('Communities') ], | ||
| 11 | - [ { :controller => 'search', :action => 'assets', :asset => 'comments'}, "icon-menu-comments", _('Comments') ], | 5 | + options = { :controller => 'search', :action => 'assets', :category_path => (@category ? @category.explode_path : []) } |
| 6 | + [ | ||
| 7 | + [ options.merge(:asset => 'articles'), "icon-menu-articles", _('Articles') ], | ||
| 8 | + [ options.merge(:asset => 'people'), "icon-menu-people", _('People') ], | ||
| 9 | + [ options.merge(:asset => 'products'), "icon-menu-product", _('Products') ], | ||
| 10 | + [ options.merge(:asset => 'enterprises'), "icon-menu-enterprise", _('Enterprises') ], | ||
| 11 | + [ options.merge(:asset => 'communities'), "icon-menu-community", _('Communities') ], | ||
| 12 | + [ options.merge(:asset => 'comments'), "icon-menu-comments", _('Comments') ], | ||
| 12 | 13 | ||
| 13 | ].map do |target,css_class,name| | 14 | ].map do |target,css_class,name| |
| 14 | content_tag('li', link_to(content_tag('span', '', :class => css_class) + name, target)) | 15 | content_tag('li', link_to(content_tag('span', '', :class => css_class) + name, target)) |
| @@ -0,0 +1,25 @@ | @@ -0,0 +1,25 @@ | ||
| 1 | +require "#{File.dirname(__FILE__)}/../test_helper" | ||
| 2 | + | ||
| 3 | +class AssetsMenuTest < ActionController::IntegrationTest | ||
| 4 | + | ||
| 5 | + def setup | ||
| 6 | + parent = Category.create!(:name => "Parent Category", :environment => Environment.default, :display_color => 1) | ||
| 7 | + @category = Category.create!(:name => "Category A", :environment => Environment.default, :parent => parent) | ||
| 8 | + end | ||
| 9 | + | ||
| 10 | + should 'link to uncategorized assets at site root' do | ||
| 11 | + get '/' | ||
| 12 | + assert_tag :tag => 'a', :attributes => { :href => '/cat/parent-category/category-a' } | ||
| 13 | + end | ||
| 14 | + | ||
| 15 | + should 'link to assets inside category root' do | ||
| 16 | + get '/cat/parent-category/category-a' | ||
| 17 | + assert_tag :tag => 'a', :attributes => { :href => '/assets/articles/parent-category/category-a' } | ||
| 18 | + end | ||
| 19 | + | ||
| 20 | + should 'link to other assets in same category when' do | ||
| 21 | + get '/assets/articles/parent-category/category-a' | ||
| 22 | + assert_tag :tag => 'a', :attributes => { :href => '/assets/products/parent-category/category-a' } | ||
| 23 | + end | ||
| 24 | + | ||
| 25 | +end |
test/unit/assets_helper_test.rb
| @@ -12,14 +12,30 @@ class ApplicationHelperTest < Test::Unit::TestCase | @@ -12,14 +12,30 @@ class ApplicationHelperTest < Test::Unit::TestCase | ||
| 12 | communities | 12 | communities |
| 13 | comments | 13 | comments |
| 14 | ].each do |asset| | 14 | ].each do |asset| |
| 15 | - expects(:link_to).with(anything, { :controller => 'search', :action => 'assets', :asset => asset}) | 15 | + expects(:link_to).with(anything, { :controller => 'search', :action => 'assets', :asset => asset, :category_path => []}) |
| 16 | end | 16 | end |
| 17 | 17 | ||
| 18 | stubs(:_).returns('') | 18 | stubs(:_).returns('') |
| 19 | stubs(:content_tag).returns('') | 19 | stubs(:content_tag).returns('') |
| 20 | generate_assets_menu | 20 | generate_assets_menu |
| 21 | - | ||
| 22 | end | 21 | end |
| 23 | 22 | ||
| 23 | + should 'generate link to assets with current category' do | ||
| 24 | + %w[ articles | ||
| 25 | + people | ||
| 26 | + products | ||
| 27 | + enterprises | ||
| 28 | + communities | ||
| 29 | + comments | ||
| 30 | + ].each do |asset| | ||
| 31 | + expects(:link_to).with(anything, { :controller => 'search', :action => 'assets', :asset => asset, :category_path => [ 'my-category' ]}) | ||
| 32 | + end | ||
| 33 | + | ||
| 34 | + stubs(:_).returns('') | ||
| 35 | + stubs(:content_tag).returns('') | ||
| 36 | + @category = mock | ||
| 37 | + @category.expects(:explode_path).returns(['my-category']).at_least_once | ||
| 38 | + generate_assets_menu | ||
| 39 | + end | ||
| 24 | 40 | ||
| 25 | end | 41 | end |