From dbd6c201d9ae21a35cf878ee83a6dadfab43e0ce Mon Sep 17 00:00:00 2001 From: vfcosta Date: Thu, 9 May 2013 11:00:45 -0300 Subject: [PATCH] accept lambda in comment_actions hot spot --- app/helpers/comment_helper.rb | 5 ++++- lib/noosfero/plugin.rb | 2 +- test/unit/comment_helper_test.rb | 9 +++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/helpers/comment_helper.rb b/app/helpers/comment_helper.rb index 5dbc092..440bf1c 100644 --- a/app/helpers/comment_helper.rb +++ b/app/helpers/comment_helper.rb @@ -31,7 +31,10 @@ module CommentHelper def links_for_comment_actions(comment) actions = [link_for_report_abuse(comment), link_for_spam(comment), link_for_edit(comment), link_for_remove(comment)] - actions += @plugins.dispatch(:comment_actions, comment) + @plugins.dispatch(:comment_actions, comment).collect do |action| + actions << (action.kind_of?(Proc) ? self.instance_eval(&action) : action) + end + actions.flatten end def link_for_report_abuse(comment) diff --git a/lib/noosfero/plugin.rb b/lib/noosfero/plugin.rb index 33a1327..83e408b 100644 --- a/lib/noosfero/plugin.rb +++ b/lib/noosfero/plugin.rb @@ -278,7 +278,7 @@ class Noosfero::Plugin end # Adds extra actions for comments - # + # returns = list of hashes or lambda block that creates a list of hashes # example: # # def comment_actions(comment) diff --git a/test/unit/comment_helper_test.rb b/test/unit/comment_helper_test.rb index 217cb35..f30e089 100644 --- a/test/unit/comment_helper_test.rb +++ b/test/unit/comment_helper_test.rb @@ -37,6 +37,15 @@ class CommentHelperTest < ActiveSupport::TestCase links = links_for_comment_actions(comment) assert_includes links, plugin_action end + + should 'include lambda actions of plugins in menu' do + comment = Comment.new + plugin_action = lambda{[{:link => 'plugin_action'}, {:link => 'plugin_action2'}]} + @plugins.stubs(:dispatch).returns([plugin_action]) + links = links_for_comment_actions(comment) + assert_includes links, {:link => 'plugin_action'} + assert_includes links, {:link => 'plugin_action2'} + end should 'return link for report abuse action when comment has a author' do comment = Comment.new -- libgit2 0.21.2