FIX: Update `last_version_at` when publishing

This commit is contained in:
Robin Ward 2018-03-26 16:06:20 -04:00
parent d4296f33ff
commit f03b6bd8c9
2 changed files with 29 additions and 17 deletions

View File

@ -7,7 +7,8 @@ class TopicPublisher
end end
def publish! def publish!
TopicTimestampChanger.new(timestamp: Time.zone.now, topic: @topic).change! do published_at = Time.zone.now
TopicTimestampChanger.new(timestamp: published_at, topic: @topic).change! do
if @topic.private_message? if @topic.private_message?
@topic = TopicConverter.new(@topic, @published_by) @topic = TopicConverter.new(@topic, @published_by)
.convert_to_public_topic(@category_id) .convert_to_public_topic(@category_id)
@ -29,8 +30,11 @@ class TopicPublisher
op = @topic.first_post op = @topic.first_post
if op.present? if op.present?
op.revisions.delete_all op.revisions.delete_all
op.update_column(:version, 1) op.update_columns(
op.update_column(:public_version, 1) version: 1,
public_version: 1,
last_version_at: published_at
)
end end
end end

View File

@ -24,22 +24,30 @@ describe TopicPublisher do
end end
it "will publish the topic properly" do it "will publish the topic properly" do
TopicPublisher.new(topic, moderator, shared_draft.category_id).publish! published_at = 1.hour.from_now.change(usec: 0)
freeze_time(published_at) do
TopicPublisher.new(topic, moderator, shared_draft.category_id).publish!
topic.reload topic.reload
expect(topic.category).to eq(category) expect(topic.category).to eq(category)
expect(topic).to be_visible expect(topic).to be_visible
expect(topic.shared_draft).to be_blank expect(topic.created_at).to eq(published_at)
expect(UserHistory.where( expect(topic.updated_at).to eq(published_at)
acting_user_id: moderator.id, expect(topic.shared_draft).to be_blank
action: UserHistory.actions[:topic_published] expect(UserHistory.where(
)).to be_present acting_user_id: moderator.id,
op.reload action: UserHistory.actions[:topic_published]
)).to be_present
op.reload
# Should delete any edits on the OP # Should delete any edits on the OP
expect(op.revisions.size).to eq(0) expect(op.revisions.size).to eq(0)
expect(op.version).to eq(1) expect(op.version).to eq(1)
expect(op.public_version).to eq(1) expect(op.public_version).to eq(1)
expect(op.created_at).to eq(published_at)
expect(op.updated_at).to eq(published_at)
expect(op.last_version_at).to eq(published_at)
end
end end
end end