mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-02-17 04:01:29 -05:00
FIX: don't count mentions in oneboxes
This commit is contained in:
parent
b052179ae6
commit
80f258e51c
2 changed files with 9 additions and 5 deletions
|
@ -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!(/^@/, '') }
|
||||
|
|
|
@ -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("<p>Hello <span class=\"mention\">@Jake</span><br><a href=\"https://twitter.com/evil_trout/status/345954894420787200\" class=\"onebox\" target=\"_blank\" rel=\"nofollow\">@Finn</a></p>")
|
||||
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'])
|
||||
|
|
Loading…
Reference in a new issue