FIX: After moving the posts topic timestamp should be updated with newest post
This commit is contained in:
parent
b4aad15267
commit
e8559f222c
|
@ -47,7 +47,7 @@ class PostMover
|
|||
notify_users_that_posts_have_moved
|
||||
update_statistics
|
||||
update_user_actions
|
||||
set_last_post_user_id(destination_topic)
|
||||
update_last_post_stats
|
||||
|
||||
if moving_all_posts
|
||||
@original_topic.update_status('closed', true, @user)
|
||||
|
@ -204,9 +204,15 @@ class PostMover
|
|||
end
|
||||
end
|
||||
|
||||
def set_last_post_user_id(topic)
|
||||
user_id = topic.posts.last.user_id rescue nil
|
||||
return if user_id.nil?
|
||||
topic.update_attribute :last_post_user_id, user_id
|
||||
def update_last_post_stats
|
||||
post = destination_topic.posts.where.not(post_type: Post.types[:whisper]).last
|
||||
if post && post_ids.include?(post.id)
|
||||
attrs = {}
|
||||
attrs[:last_posted_at] = post.created_at
|
||||
attrs[:last_post_user_id] = post.user_id
|
||||
attrs[:bumped_at] = post.created_at unless post.no_bump
|
||||
attrs[:updated_at] = 'now()'
|
||||
destination_topic.update_columns(attrs)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -192,8 +192,11 @@ describe PostMover do
|
|||
new_topic.reload
|
||||
expect(new_topic.posts_count).to eq(2)
|
||||
expect(new_topic.highest_post_number).to eq(2)
|
||||
expect(new_topic.last_post_user_id).to eq(new_topic.posts.last.user_id)
|
||||
expect(new_topic.last_posted_at).to be_present
|
||||
|
||||
last_post = new_topic.posts.last
|
||||
expect(new_topic.last_post_user_id).to eq(last_post.user_id)
|
||||
expect(new_topic.last_posted_at).to eq(last_post.created_at)
|
||||
expect(new_topic.bumped_at).to eq(last_post.created_at)
|
||||
|
||||
p2.reload
|
||||
expect(p2.sort_order).to eq(1)
|
||||
|
|
Loading…
Reference in New Issue