FIX: Don't include reflections when checking for duplication topic links.

This commit is contained in:
Guo Xiang Tan 2016-06-13 13:13:39 +08:00
parent 8c3e63f87a
commit 1fe499e893
No known key found for this signature in database
GPG key ID: 19C321C8952B0F72
2 changed files with 29 additions and 1 deletions

View file

@ -233,7 +233,8 @@ class TopicLink < ActiveRecord::Base
results = TopicLink results = TopicLink
.includes(:post => :user) .includes(:post => :user)
.where(topic_id: topic.id).limit(200) .where(topic_id: topic.id, reflection: false)
.limit(200)
lookup = {} lookup = {}
results.each do |tl| results.each do |tl|

View file

@ -16,6 +16,8 @@ describe TopicLink do
topic.user topic.user
end end
let(:post) { Fabricate(:post) }
it "can't link to the same topic" do it "can't link to the same topic" do
ftl = TopicLink.new(url: "/t/#{topic.id}", ftl = TopicLink.new(url: "/t/#{topic.id}",
topic_id: topic.id, topic_id: topic.id,
@ -320,6 +322,31 @@ http://b.com/#{'a'*500}
end end
end end
describe ".duplicate_lookup" do
let(:user) { Fabricate(:user, username: "junkrat") }
let(:post_with_internal_link) do
Fabricate(:post, user: user, raw: "Check out this topic #{post.topic.url}/122131")
end
it "should return the right response" do
TopicLink.extract_from(post_with_internal_link)
result = TopicLink.duplicate_lookup(post_with_internal_link.topic)
expect(result.count).to eq(1)
lookup = result["test.localhost/t/#{post.topic.slug}/#{post.topic.id}/122131"]
expect(lookup[:domain]).to eq("test.localhost")
expect(lookup[:username]).to eq("junkrat")
expect(lookup[:posted_at].to_s).to eq(post_with_internal_link.created_at.to_s)
expect(lookup[:post_number]).to eq(1)
result = TopicLink.duplicate_lookup(post.topic)
expect(result.count).to eq(0)
end
end
end end
end end