FIX: Moving a post should also update its TopicLink records

This commit is contained in:
Robin Ward 2013-07-02 16:42:25 -04:00
parent 22e6b3f466
commit 05fe33111e
2 changed files with 6 additions and 1 deletions

View File

@ -79,6 +79,9 @@ class PostMover
id: post.id,
topic_id: original_topic.id
)
# Move any links from the post to the new topic
post.topic_links.update_all(topic_id: destination_topic.id)
end
def update_statistics

View File

@ -234,7 +234,7 @@ describe Topic do
let(:category) { Fabricate(:category, user: user) }
let!(:topic) { Fabricate(:topic, user: user, category: category) }
let!(:p1) { Fabricate(:post, topic: topic, user: user) }
let!(:p2) { Fabricate(:post, topic: topic, user: another_user)}
let!(:p2) { Fabricate(:post, topic: topic, user: another_user, raw: "Has a link to [evil trout](http://eviltrout.com) which is a cool site.")}
let!(:p3) { Fabricate(:post, topic: topic, user: user)}
let!(:p4) { Fabricate(:post, topic: topic, user: user)}
@ -279,6 +279,7 @@ describe Topic do
before do
topic.expects(:add_moderator_post)
TopicUser.update_last_read(user, topic.id, p4.post_number, 0)
TopicLink.extract_from(p2)
end
context "to a new topic" do
@ -303,6 +304,7 @@ describe Topic do
p2.reload
p2.sort_order.should == 1
p2.post_number.should == 1
p2.topic_links.first.topic_id.should == new_topic.id
p4.reload
p4.post_number.should == 2