Commit aa2c4349df0f1075885b28f5880603f508205c86

Authored by Victor Costa
1 parent 45813640

comment_paragraph: apply macro only for content viewer controller

plugins/comment_paragraph/lib/comment_paragraph_plugin/macros/allow_comment.rb
@@ -12,8 +12,12 @@ class CommentParagraphPlugin::AllowComment < Noosfero::Plugin::Macro @@ -12,8 +12,12 @@ class CommentParagraphPlugin::AllowComment < Noosfero::Plugin::Macro
12 count = article.paragraph_comments.without_spam.in_paragraph(paragraph_uuid).count 12 count = article.paragraph_comments.without_spam.in_paragraph(paragraph_uuid).count
13 13
14 proc { 14 proc {
15 - render :partial => 'comment_paragraph_plugin_profile/comment_paragraph',  
16 - :locals => {:paragraph_uuid => paragraph_uuid, :article_id => article.id, :inner_html => inner_html, :count => count, :profile_identifier => article.profile.identifier } 15 + if controller.kind_of?(ContentViewerController)
  16 + render :partial => 'comment_paragraph_plugin_profile/comment_paragraph',
  17 + :locals => {:paragraph_uuid => paragraph_uuid, :article_id => article.id, :inner_html => inner_html, :count => count, :profile_identifier => article.profile.identifier }
  18 + else
  19 + inner_html
  20 + end
17 } 21 }
18 end 22 end
19 end 23 end
plugins/comment_paragraph/test/unit/allow_comment_test.rb
@@ -18,9 +18,21 @@ class AllowCommentTest < ActiveSupport::TestCase @@ -18,9 +18,21 @@ class AllowCommentTest < ActiveSupport::TestCase
18 comment = fast_create(Comment, :paragraph_uuid => 1, :source_id => article.id) 18 comment = fast_create(Comment, :paragraph_uuid => 1, :source_id => article.id)
19 inner_html = 'inner' 19 inner_html = 'inner'
20 content = macro.parse({:paragraph_uuid => comment.paragraph_uuid}, inner_html, article) 20 content = macro.parse({:paragraph_uuid => comment.paragraph_uuid}, inner_html, article)
  21 + expects(:controller).returns(ContentViewerController.new)
21 22
22 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} }) 23 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} })
23 instance_eval(&content) 24 instance_eval(&content)
24 end 25 end
25 26
  27 + should 'not parse contents outside content viewer controller' do
  28 + profile = fast_create(Community)
  29 + article = fast_create(Article, :profile_id => profile.id)
  30 + comment = fast_create(Comment, :paragraph_uuid => 1, :source_id => article.id)
  31 + inner_html = 'inner'
  32 + content = macro.parse({:paragraph_uuid => comment.paragraph_uuid}, inner_html, article)
  33 + expects(:controller).returns(HomeController.new)
  34 +
  35 + assert_equal 'inner', instance_eval(&content)
  36 + end
  37 +
26 end 38 end