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
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?
@topic = TopicConverter.new(@topic, @published_by)
.convert_to_public_topic(@category_id)
@ -29,8 +30,11 @@ class TopicPublisher
op = @topic.first_post
if op.present?
op.revisions.delete_all
op.update_column(:version, 1)
op.update_column(:public_version, 1)
op.update_columns(
version: 1,
public_version: 1,
last_version_at: published_at
)
end
end

View File

@ -24,22 +24,30 @@ describe TopicPublisher do
end
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
expect(topic.category).to eq(category)
expect(topic).to be_visible
expect(topic.shared_draft).to be_blank
expect(UserHistory.where(
acting_user_id: moderator.id,
action: UserHistory.actions[:topic_published]
)).to be_present
op.reload
topic.reload
expect(topic.category).to eq(category)
expect(topic).to be_visible
expect(topic.created_at).to eq(published_at)
expect(topic.updated_at).to eq(published_at)
expect(topic.shared_draft).to be_blank
expect(UserHistory.where(
acting_user_id: moderator.id,
action: UserHistory.actions[:topic_published]
)).to be_present
op.reload
# Should delete any edits on the OP
expect(op.revisions.size).to eq(0)
expect(op.version).to eq(1)
expect(op.public_version).to eq(1)
# Should delete any edits on the OP
expect(op.revisions.size).to eq(0)
expect(op.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