From 09e53c72d48f71eca17c3231ccdff5359b5bf8b9 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Mon, 11 Feb 2013 12:27:32 -0500 Subject: [PATCH] Changed our minds: Let's track internal links, just never to users. Something like FAQ is useful. --- app/models/topic_link.rb | 7 ++++--- spec/models/topic_link_spec.rb | 13 ++++++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/app/models/topic_link.rb b/app/models/topic_link.rb index 66b596a3ce3..d4215ae8128 100644 --- a/app/models/topic_link.rb +++ b/app/models/topic_link.rb @@ -47,11 +47,12 @@ class TopicLink < ActiveRecord::Base internal = true route = Rails.application.routes.recognize_path(parsed.path) + + # We aren't interested in tracking internal links to users + next if route[:controller] == 'users' + 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 diff --git a/spec/models/topic_link_spec.rb b/spec/models/topic_link_spec.rb index ea3ef74d555..b158ccf8628 100644 --- a/spec/models/topic_link_spec.rb +++ b/spec/models/topic_link_spec.rb @@ -143,7 +143,7 @@ describe TopicLink do end - context "link to a non-topic on discourse" do + context "link to a user on discourse" do let(:post) { @topic.posts.create(user: @user, raw: "user") } before do TopicLink.extract_from(post) @@ -154,6 +154,17 @@ describe TopicLink do end end + context "link to a discourse resource like a FAQ" do + let(:post) { @topic.posts.create(user: @user, raw: "faq link here") } + before do + TopicLink.extract_from(post) + end + + it 'does not extract a link' do + @topic.topic_links.should be_present + end + end + context "@mention links" do let(:post) { @topic.posts.create(user: @user, raw: "Hey @#{@user.username_lower}") }