mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -05:00
Don't track links within discourse unless they're to other topics.
This commit is contained in:
parent
37fa61ab51
commit
f21609fe2e
2 changed files with 101 additions and 95 deletions
|
@ -49,6 +49,9 @@ class TopicLink < ActiveRecord::Base
|
|||
route = Rails.application.routes.recognize_path(parsed.path)
|
||||
topic_id = route[:topic_id]
|
||||
post_number = route[:post_number] || 1
|
||||
|
||||
# We aren't interested in tracking internal links to non-topics
|
||||
next unless topic_id
|
||||
end
|
||||
|
||||
# Skip linking to ourselves
|
||||
|
|
|
@ -44,31 +44,9 @@ describe TopicLink do
|
|||
|
||||
end
|
||||
|
||||
describe 'domain-less link' do
|
||||
let(:post) { @topic.posts.create(user: @user, raw: "<a href='/users'>hello</a>") }
|
||||
let!(:link) do
|
||||
TopicLink.extract_from(post)
|
||||
@topic.topic_links.first
|
||||
end
|
||||
|
||||
it 'is extracted' do
|
||||
link.should be_present
|
||||
end
|
||||
|
||||
it 'has the correct domain' do
|
||||
link.domain.should == test_uri.host
|
||||
end
|
||||
|
||||
it "is not destroyed when we call extract from again" do
|
||||
TopicLink.extract_from(post)
|
||||
link.reload
|
||||
link.should be_present
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'internal links' do
|
||||
|
||||
context 'topic link' do
|
||||
before do
|
||||
@other_topic = Fabricate(:topic, user: @user)
|
||||
@other_post = @other_topic.posts.create(user: @user, raw: "some content")
|
||||
|
@ -165,6 +143,31 @@ describe TopicLink do
|
|||
|
||||
end
|
||||
|
||||
context "link to a non-topic on discourse" do
|
||||
let(:post) { @topic.posts.create(user: @user, raw: "<a href='/users/#{@user.username_lower}'>user</a>") }
|
||||
before do
|
||||
TopicLink.extract_from(post)
|
||||
end
|
||||
|
||||
it 'does not extract a link' do
|
||||
@topic.topic_links.should be_blank
|
||||
end
|
||||
end
|
||||
|
||||
context "@mention links" do
|
||||
let(:post) { @topic.posts.create(user: @user, raw: "Hey @#{@user.username_lower}") }
|
||||
|
||||
before do
|
||||
TopicLink.extract_from(post)
|
||||
end
|
||||
|
||||
it 'does not extract a link' do
|
||||
@topic.topic_links.should be_blank
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'internal link from pm' do
|
||||
before do
|
||||
@pm = Fabricate(:topic, user: @user, archetype: 'private_message')
|
||||
|
|
Loading…
Reference in a new issue