From f03b6bd8c925163b41b9e33b39484d102dbaee44 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Mon, 26 Mar 2018 16:06:20 -0400 Subject: [PATCH] FIX: Update `last_version_at` when publishing --- lib/topic_publisher.rb | 10 ++++--- spec/components/topic_publisher_spec.rb | 36 +++++++++++++++---------- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/lib/topic_publisher.rb b/lib/topic_publisher.rb index 5003f70cb52..a7cecb7e4fc 100644 --- a/lib/topic_publisher.rb +++ b/lib/topic_publisher.rb @@ -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 diff --git a/spec/components/topic_publisher_spec.rb b/spec/components/topic_publisher_spec.rb index aed3bce232f..43d33172f58 100644 --- a/spec/components/topic_publisher_spec.rb +++ b/spec/components/topic_publisher_spec.rb @@ -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