A platform for community discussion. Free, open, simple.
FIX: Update `last_version_at` when publishing
Robin Wardf03b6bd8c925
diff --git a/lib/topic_publisher.rb b/lib/topic_publisher.rbindex 5003f70cb52..a7cecb7e4fc 100644--- a/lib/topic_publisher.rb+++ b/lib/topic_publisher.rb@@ -7,7 +7,8 @@ class TopicPublisherenddef publish!- TopicTimestampChanger.new(timestamp: Time.zone.now, topic: @topic).change! do+ published_at = Time.zone.now+ TopicTimestampChanger.new(timestamp: published_at, topic: @topic).change! doif @topic.private_message?@topic = TopicConverter.new(@topic, @published_by).convert_to_public_topic(@category_id)@@ -29,8 +30,11 @@ class TopicPublisherop = @topic.first_postif 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+ )endenddiff --git a/spec/components/topic_publisher_spec.rb b/spec/components/topic_publisher_spec.rbindex aed3bce232f..43d33172f58 100644--- a/spec/components/topic_publisher_spec.rb+++ b/spec/components/topic_publisher_spec.rb@@ -24,22 +24,30 @@ describe TopicPublisher doendit "will publish the topic properly" 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-- # 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)+ 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.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)+ 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)+ endendend