From 80f258e51c102cf0fa746a9692f0cccae1c1afac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Wed, 24 Jun 2015 11:44:58 +0200 Subject: [PATCH] FIX: don't count mentions in oneboxes --- app/models/post_analyzer.rb | 3 ++- spec/models/post_analyzer_spec.rb | 11 +++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/models/post_analyzer.rb b/app/models/post_analyzer.rb index b60502b98fc..4e2bf369e81 100644 --- a/app/models/post_analyzer.rb +++ b/app/models/post_analyzer.rb @@ -45,11 +45,12 @@ class PostAnalyzer return [] if @raw.blank? return @raw_mentions if @raw_mentions.present? - # strip quotes and code blocks + # strip quotes, code blocks and oneboxes cooked_stripped = cooked_document cooked_stripped.css("aside.quote").remove cooked_stripped.css("pre").remove cooked_stripped.css("code").remove + cooked_stripped.css(".onebox").remove results = cooked_stripped.to_html.scan(PrettyText.mention_matcher) @raw_mentions = results.uniq.map { |un| un.first.downcase.gsub!(/^@/, '') } diff --git a/spec/models/post_analyzer_spec.rb b/spec/models/post_analyzer_spec.rb index a947490bc02..f2bc5f1f334 100644 --- a/spec/models/post_analyzer_spec.rb +++ b/spec/models/post_analyzer_spec.rb @@ -3,6 +3,7 @@ require 'spec_helper' describe PostAnalyzer do let(:default_topic_id) { 12 } + let(:url) { 'https://twitter.com/evil_trout/status/345954894420787200' } describe '#cook' do let(:post_analyzer) {PostAnalyzer.new nil, nil } @@ -11,10 +12,6 @@ describe PostAnalyzer do let(:options) { {} } let(:args) { [raw, options] } - let(:url) { - 'https://twitter.com/evil_trout/status/345954894420787200' - } - before { Oneboxer.stubs(:onebox) } it 'fetches the cached onebox for any urls in the post' do @@ -198,6 +195,12 @@ describe PostAnalyzer do expect(post_analyzer.raw_mentions).to eq(['finn']) end + it "ignores oneboxes" do + post_analyzer = PostAnalyzer.new("Hello @Jake\n#{url}", default_topic_id) + post_analyzer.stubs(:cook).returns("

Hello @Jake
@Finn

") + expect(post_analyzer.raw_mentions).to eq(['jake']) + end + it "handles underscore in username" do post_analyzer = PostAnalyzer.new("@Jake @Finn @Jake_Old", default_topic_id) expect(post_analyzer.raw_mentions).to eq(['jake', 'finn', 'jake_old'])