Commit fdaee4f48def6a61aacb5e74b5c72981d65bb4cd

Authored by Victor Costa
1 parent dbd6c201

do not show comment actions menu if it has no items

app/helpers/comment_helper.rb
@@ -34,7 +34,7 @@ module CommentHelper @@ -34,7 +34,7 @@ module CommentHelper
34 @plugins.dispatch(:comment_actions, comment).collect do |action| 34 @plugins.dispatch(:comment_actions, comment).collect do |action|
35 actions << (action.kind_of?(Proc) ? self.instance_eval(&action) : action) 35 actions << (action.kind_of?(Proc) ? self.instance_eval(&action) : action)
36 end 36 end
37 - actions.flatten 37 + actions.flatten.compact
38 end 38 end
39 39
40 def link_for_report_abuse(comment) 40 def link_for_report_abuse(comment)
test/unit/comment_helper_test.rb
@@ -29,6 +29,16 @@ class CommentHelperTest &lt; ActiveSupport::TestCase @@ -29,6 +29,16 @@ class CommentHelperTest &lt; ActiveSupport::TestCase
29 menu = comment_actions(comment) 29 menu = comment_actions(comment)
30 assert !menu 30 assert !menu
31 end 31 end
  32 +
  33 + should 'do not show menu if it has nil actions only' do
  34 + comment = Comment.new
  35 + self.stubs(:link_for_report_abuse).returns(nil)
  36 + self.stubs(:link_for_spam).returns(nil)
  37 + self.stubs(:link_for_edit).returns(nil)
  38 + self.stubs(:link_for_remove).returns(nil)
  39 + menu = comment_actions(comment)
  40 + assert !menu
  41 + end
32 42
33 should 'include actions of plugins in menu' do 43 should 'include actions of plugins in menu' do
34 comment = Comment.new 44 comment = Comment.new