diff --git a/app/models/topic_link.rb b/app/models/topic_link.rb index 27735689d85..2f7cc745236 100644 --- a/app/models/topic_link.rb +++ b/app/models/topic_link.rb @@ -161,7 +161,7 @@ class TopicLink < ActiveRecord::Base added_urls << url topic_link = TopicLink.find_by(topic_id: post.topic_id, - user_id: post.user_id, + post_id: post.id, url: url) unless topic_link diff --git a/spec/models/topic_link_spec.rb b/spec/models/topic_link_spec.rb index 5aca2837b17..314276a26dd 100644 --- a/spec/models/topic_link_spec.rb +++ b/spec/models/topic_link_spec.rb @@ -121,6 +121,16 @@ http://b.com/#{'a'*500} expect(reflection.user_id).to eq(link.user_id) end + PostOwnerChanger.new( + post_ids: [linked_post.id], + topic_id: topic.id, + acting_user: user, + new_owner: Fabricate(:user) + ).change_owner! + + TopicLink.extract_from(linked_post) + expect(topic.topic_links.first.url).to eq(url) + linked_post.revise(post.user, { raw: "no more linkies https://eviltrout.com" }) expect(other_topic.topic_links.where(link_post_id: linked_post.id)).to be_blank end