Commit dbd6c201d9ae21a35cf878ee83a6dadfab43e0ce
1 parent
0770524c
Exists in
master
and in
29 other branches
accept lambda in comment_actions hot spot
Showing
3 changed files
with
14 additions
and
2 deletions
Show diff stats
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
test/unit/comment_helper_test.rb
... | ... | @@ -37,6 +37,15 @@ class CommentHelperTest < 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 | ... | ... |