mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -05:00
Don't count @mentions as links in a post
This commit is contained in:
parent
6568b4aaa9
commit
c372e36cb6
2 changed files with 19 additions and 4 deletions
|
@ -110,7 +110,17 @@ class Post < ActiveRecord::Base
|
|||
|
||||
def link_count
|
||||
return 0 unless raw.present?
|
||||
cooked_document.search("a[href]").count
|
||||
|
||||
# Don't include @mentions in the link count
|
||||
total = 0
|
||||
cooked_document.search("a[href]").each do |l|
|
||||
html_class = l.attributes['class']
|
||||
if html_class.present?
|
||||
next if html_class.to_s == 'mention' && l.attributes['href'].to_s =~ /^\/users\//
|
||||
end
|
||||
total +=1
|
||||
end
|
||||
total
|
||||
end
|
||||
|
||||
def max_mention_validator
|
||||
|
|
|
@ -149,16 +149,21 @@ describe Post do
|
|||
let(:visitor) { Fabricate(:user, trust_level: TrustLevel.levels[:visitor]) }
|
||||
let(:post_one_link) { Fabricate.build(:post, post_args.merge(raw: "[sherlock](http://www.bbc.co.uk/programmes/b018ttws)", user: visitor)) }
|
||||
let(:post_two_links) { Fabricate.build(:post, post_args.merge(raw: "<a href='http://discourse.org'>discourse</a> <a href='http://twitter.com'>twitter</a>", user: visitor)) }
|
||||
let(:post_with_mentions) { Fabricate.build(:post, post_args.merge(raw: "hello @#{visitor.username} how are you doing?") )}
|
||||
|
||||
it "returns 0 images for an empty post" do
|
||||
it "returns 0 links for an empty post" do
|
||||
Fabricate.build(:post).link_count.should == 0
|
||||
end
|
||||
|
||||
it "finds images from markdown" do
|
||||
it "returns 0 links for a post with mentions" do
|
||||
post_with_mentions.link_count.should == 0
|
||||
end
|
||||
|
||||
it "finds links from markdown" do
|
||||
post_one_link.link_count.should == 1
|
||||
end
|
||||
|
||||
it "finds images from HTML" do
|
||||
it "finds links from HTML" do
|
||||
post_two_links.link_count.should == 2
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue