FIX: Topic#last_posted_at was not being set when changing topic timestamp.

This commit is contained in:
Guo Xiang Tan 2015-10-20 10:12:52 +08:00
parent 50d2ba5f8e
commit d9fe78da20
2 changed files with 11 additions and 4 deletions

View File

@ -8,15 +8,19 @@ class PostTimestampChanger
def change!
ActiveRecord::Base.transaction do
update_topic
last_posted_at = @timestamp
@posts.each do |post|
if post.is_first_post?
update_post(post, @timestamp)
else
update_post(post, Time.at(post.created_at.to_f + @time_difference))
new_created_at = Time.at(post.created_at.to_f + @time_difference)
last_posted_at = new_created_at if new_created_at > last_posted_at
update_post(post, new_created_at)
end
end
update_topic(last_posted_at)
end
# Burst the cache for stats
@ -29,11 +33,12 @@ class PostTimestampChanger
@timestamp - @topic.created_at
end
def update_topic
def update_topic(last_posted_at)
@topic.update_attributes(
created_at: @timestamp,
updated_at: @timestamp,
bumped_at: @timestamp
bumped_at: @timestamp,
last_posted_at: last_posted_at
)
end

View File

@ -21,6 +21,8 @@ describe PostTimestampChanger do
[:created_at, :updated_at].each do |column|
expect(p1.public_send(column)).to be_within_one_second_of(new_timestamp)
end
expect(topic.last_posted_at).to be_within_one_second_of(p2.reload.created_at)
end
describe 'predated timestamp' do