Commit dbd6c201d9ae21a35cf878ee83a6dadfab43e0ce

Authored by Victor Costa
1 parent 0770524c

accept lambda in comment_actions hot spot

app/helpers/comment_helper.rb
... ... @@ -31,7 +31,10 @@ module CommentHelper
31 31  
32 32 def links_for_comment_actions(comment)
33 33 actions = [link_for_report_abuse(comment), link_for_spam(comment), link_for_edit(comment), link_for_remove(comment)]
34   - actions += @plugins.dispatch(:comment_actions, comment)
  34 + @plugins.dispatch(:comment_actions, comment).collect do |action|
  35 + actions << (action.kind_of?(Proc) ? self.instance_eval(&action) : action)
  36 + end
  37 + actions.flatten
35 38 end
36 39  
37 40 def link_for_report_abuse(comment)
... ...
lib/noosfero/plugin.rb
... ... @@ -278,7 +278,7 @@ class Noosfero::Plugin
278 278 end
279 279  
280 280 # Adds extra actions for comments
281   - #
  281 + # returns = list of hashes or lambda block that creates a list of hashes
282 282 # example:
283 283 #
284 284 # def comment_actions(comment)
... ...
test/unit/comment_helper_test.rb
... ... @@ -37,6 +37,15 @@ class CommentHelperTest &lt; ActiveSupport::TestCase
37 37 links = links_for_comment_actions(comment)
38 38 assert_includes links, plugin_action
39 39 end
  40 +
  41 + should 'include lambda actions of plugins in menu' do
  42 + comment = Comment.new
  43 + plugin_action = lambda{[{:link => 'plugin_action'}, {:link => 'plugin_action2'}]}
  44 + @plugins.stubs(:dispatch).returns([plugin_action])
  45 + links = links_for_comment_actions(comment)
  46 + assert_includes links, {:link => 'plugin_action'}
  47 + assert_includes links, {:link => 'plugin_action2'}
  48 + end
40 49  
41 50 should 'return link for report abuse action when comment has a author' do
42 51 comment = Comment.new
... ...