FIX: topic link reflections deleted on second save
This commit is contained in:
parent
a496574e93
commit
65f466cf8c
|
@ -178,6 +178,16 @@ class TopicLink < ActiveRecord::Base
|
|||
prefix = Discourse.base_url_no_prefix
|
||||
|
||||
reflected_url = "#{prefix}#{post.topic.relative_url(post.post_number)}"
|
||||
|
||||
tl = TopicLink.find_by(topic_id: topic_id,
|
||||
post_id: reflected_post.try(:id),
|
||||
url: reflected_url)
|
||||
|
||||
if tl
|
||||
tl.update_columns(domain: Discourse.current_hostname,
|
||||
link_topic_id: post.topic.id,
|
||||
link_post_id: post.id)
|
||||
else
|
||||
tl = TopicLink.create(user_id: post.user_id,
|
||||
topic_id: topic_id,
|
||||
post_id: reflected_post.try(:id),
|
||||
|
@ -188,6 +198,8 @@ class TopicLink < ActiveRecord::Base
|
|||
link_topic_id: post.topic_id,
|
||||
link_post_id: post.id)
|
||||
|
||||
end
|
||||
|
||||
reflected_ids << tl.try(:id)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -92,6 +92,10 @@ http://b.com/#{'a'*500}
|
|||
topic.posts.create(user: user, raw: 'initial post')
|
||||
linked_post = topic.posts.create(user: user, raw: "Link to another topic: #{url}")
|
||||
|
||||
# this is subtle, but we had a bug were second time
|
||||
# TopicLink.extract_from was called a reflection was nuked
|
||||
2.times do
|
||||
topic.reload
|
||||
TopicLink.extract_from(linked_post)
|
||||
|
||||
link = topic.topic_links.first
|
||||
|
@ -113,6 +117,7 @@ http://b.com/#{'a'*500}
|
|||
expect(reflection.link_post_id).to eq(linked_post.id)
|
||||
|
||||
expect(reflection.user_id).to eq(link.user_id)
|
||||
end
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue