From d5f5fbd0895c67584a9a6610bb8bcce9cc165630 Mon Sep 17 00:00:00 2001 From: Leandro Nunes dos Santos Date: Mon, 2 Mar 2015 16:58:36 -0300 Subject: [PATCH] replace Hpricot to Nokogiri --- plugins/comment_paragraph/lib/ext/article.rb | 6 +++--- plugins/comment_paragraph/test/unit/allow_comment_test.rb | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/comment_paragraph/lib/ext/article.rb b/plugins/comment_paragraph/lib/ext/article.rb index ab19aac..0ef3d23 100644 --- a/plugins/comment_paragraph/lib/ext/article.rb +++ b/plugins/comment_paragraph/lib/ext/article.rb @@ -21,12 +21,12 @@ class Article def comment_paragraph_plugin_parse_html comment_paragraph_plugin_set_initial_value unless persisted? return unless comment_paragraph_plugin_activated? - if body && (body_changed? || setting_changed?(:comment_paragraph_plugin_activate)) parsed_paragraphs = [] updated = body_changed? ? body_change[1] : body - doc = Hpricot(updated) - doc.search("/*").each do |paragraph| + doc = Nokogiri::HTML(updated).css('body') + + doc.children.each do |paragraph| if paragraph.to_html =~ /^\W<\/p>$/ parsed_paragraphs << paragraph.to_html else diff --git a/plugins/comment_paragraph/test/unit/allow_comment_test.rb b/plugins/comment_paragraph/test/unit/allow_comment_test.rb index 503d763..121977a 100644 --- a/plugins/comment_paragraph/test/unit/allow_comment_test.rb +++ b/plugins/comment_paragraph/test/unit/allow_comment_test.rb @@ -32,12 +32,14 @@ class AllowCommentTest < ActiveSupport::TestCase end should 'not parse contents outside content viewer controller' do + article = fast_create(TextArticle, :profile_id => profile.id, :body => 'inner') content = macro.parse({:paragraph_uuid => comment.paragraph_uuid}, article.body, article) controller.expects(:kind_of?).with(ContentViewerController).returns(false) assert_equal 'inner', instance_eval(&content) end should 'not parse contents if comment_paragraph is not activated' do + article = fast_create(TextArticle, :profile_id => profile.id, :body => 'inner') article.expects(:comment_paragraph_plugin_activated?).returns(false) content = macro.parse({:paragraph_uuid => comment.paragraph_uuid}, article.body, article) controller.expects(:kind_of?).with(ContentViewerController).returns(true) -- libgit2 0.21.2