From 5b9ea2513b90770ccafd42e5ce571090b2f4fc3f Mon Sep 17 00:00:00 2001 From: Melissa Wen Date: Thu, 12 Nov 2015 16:20:34 -0200 Subject: [PATCH] Include some profile controller paths to show breadcrumbs block --- plugins/breadcrumbs/lib/breadcrumbs_plugin/content_breadcrumbs_block.rb | 8 ++++++++ plugins/breadcrumbs/test/unit/content_breadcrumbs_block_test.rb | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+), 0 deletions(-) diff --git a/plugins/breadcrumbs/lib/breadcrumbs_plugin/content_breadcrumbs_block.rb b/plugins/breadcrumbs/lib/breadcrumbs_plugin/content_breadcrumbs_block.rb index dbc2a0c..9d3db60 100644 --- a/plugins/breadcrumbs/lib/breadcrumbs_plugin/content_breadcrumbs_block.rb +++ b/plugins/breadcrumbs/lib/breadcrumbs_plugin/content_breadcrumbs_block.rb @@ -23,6 +23,9 @@ class BreadcrumbsPlugin::ContentBreadcrumbsBlock < Block id = params[:id] || params[:parent_id] links = page_trail(Article.find(id)) if id links << { :name => cms_action(params[:action]), :url => params } if show_cms_action + elsif (params[:controller] == 'profile' || params[:controller] == 'events') + links << { :name => _('Profile'), :url => {:controller=> 'profile', :action =>'index', :profile =>params[:profile]}} + links << { :name => profile_action(params[:action]), :url => params } unless params[:action] == 'index' end links end @@ -66,9 +69,14 @@ class BreadcrumbsPlugin::ContentBreadcrumbsBlock < Block protected CMS_ACTIONS = {:edit => c_('Edit'), :upload_files => _('Upload Files'), :new => c_('New')} + PROFILE_ACTIONS = {:members => _('Members'), :events => _('Events')} def cms_action(action) CMS_ACTIONS[action.to_sym] || action end + def profile_action(action) + PROFILE_ACTIONS[action.to_sym] || action + end + end diff --git a/plugins/breadcrumbs/test/unit/content_breadcrumbs_block_test.rb b/plugins/breadcrumbs/test/unit/content_breadcrumbs_block_test.rb index e26d048..2c4c88c 100644 --- a/plugins/breadcrumbs/test/unit/content_breadcrumbs_block_test.rb +++ b/plugins/breadcrumbs/test/unit/content_breadcrumbs_block_test.rb @@ -40,6 +40,24 @@ class ContentBreadcrumbsBlockTest < ActiveSupport::TestCase assert_equal links, @block.page_trail(nil, params) end + should 'include profile page link on path of links to reach a profile controller page' do + params = {:controller => 'profile', :action => 'members', :profile => @profile.identifier} + links = [{:name => 'Profile', :url => {:controller => 'profile', :action => 'index', :profile => @profile.identifier}}, {:name => 'Members', :url => {:controller=>'profile', :action=>'members', :profile=> @profile.identifier}}] + assert_equal links, @block.page_trail(nil, params) + end + + should 'include only the profile page link on path links when profile action is index' do + params = {:controller => 'profile', :action => 'index', :profile => @profile.identifier} + links = [{:name => 'Profile', :url => {:controller => 'profile', :action => 'index', :profile => @profile.identifier}}] + assert_equal links, @block.page_trail(nil, params) + end + + should 'profile page be the ancestor page of event profile page calendar' do + params = {:controller => 'profile', :action => 'events', :profile => @profile.identifier} + links = [{:name => 'Profile', :url => {:controller => 'profile', :action => 'index', :profile => @profile.identifier}}, {:name => 'Events', :url => {:controller=>'profile', :action=>'events', :profile=> @profile.identifier}}] + assert_equal links, @block.page_trail(nil, params) + end + should 'include profile link on path of links to reach a page' do links = [{:name => @profile.name, :url => @profile.url}, {:name => @folder.name, :url => @folder.url}, {:name => @article.name, :url => @article.url}] assert_equal links, @block.trail(@article, @profile) -- libgit2 0.21.2