diff --git a/plugins/comment_paragraph/lib/comment_paragraph_plugin/macros/allow_comment.rb b/plugins/comment_paragraph/lib/comment_paragraph_plugin/macros/allow_comment.rb index 5c0a813..55c641e 100644 --- a/plugins/comment_paragraph/lib/comment_paragraph_plugin/macros/allow_comment.rb +++ b/plugins/comment_paragraph/lib/comment_paragraph_plugin/macros/allow_comment.rb @@ -12,8 +12,12 @@ class CommentParagraphPlugin::AllowComment < Noosfero::Plugin::Macro count = article.paragraph_comments.without_spam.in_paragraph(paragraph_uuid).count proc { - render :partial => 'comment_paragraph_plugin_profile/comment_paragraph', - :locals => {:paragraph_uuid => paragraph_uuid, :article_id => article.id, :inner_html => inner_html, :count => count, :profile_identifier => article.profile.identifier } + if controller.kind_of?(ContentViewerController) + render :partial => 'comment_paragraph_plugin_profile/comment_paragraph', + :locals => {:paragraph_uuid => paragraph_uuid, :article_id => article.id, :inner_html => inner_html, :count => count, :profile_identifier => article.profile.identifier } + else + inner_html + end } end end diff --git a/plugins/comment_paragraph/test/unit/allow_comment_test.rb b/plugins/comment_paragraph/test/unit/allow_comment_test.rb index 2b550cc..e69fa77 100644 --- a/plugins/comment_paragraph/test/unit/allow_comment_test.rb +++ b/plugins/comment_paragraph/test/unit/allow_comment_test.rb @@ -18,9 +18,21 @@ class AllowCommentTest < ActiveSupport::TestCase comment = fast_create(Comment, :paragraph_uuid => 1, :source_id => article.id) inner_html = 'inner' content = macro.parse({:paragraph_uuid => comment.paragraph_uuid}, inner_html, article) + expects(:controller).returns(ContentViewerController.new) expects(:render).with({:partial => 'comment_paragraph_plugin_profile/comment_paragraph', :locals => {:paragraph_uuid => comment.paragraph_uuid, :article_id => article.id, :inner_html => inner_html, :count => 1, :profile_identifier => profile.identifier} }) instance_eval(&content) end + should 'not parse contents outside content viewer controller' do + profile = fast_create(Community) + article = fast_create(Article, :profile_id => profile.id) + comment = fast_create(Comment, :paragraph_uuid => 1, :source_id => article.id) + inner_html = 'inner' + content = macro.parse({:paragraph_uuid => comment.paragraph_uuid}, inner_html, article) + expects(:controller).returns(HomeController.new) + + assert_equal 'inner', instance_eval(&content) + end + end -- libgit2 0.21.2