FIX: Update `last_version_at` when publishing
This commit is contained in:
parent
d4296f33ff
commit
f03b6bd8c9
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -24,11 +24,15 @@ describe TopicPublisher do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "will publish the topic properly" do
|
it "will publish the topic properly" do
|
||||||
|
published_at = 1.hour.from_now.change(usec: 0)
|
||||||
|
freeze_time(published_at) do
|
||||||
TopicPublisher.new(topic, moderator, shared_draft.category_id).publish!
|
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.created_at).to eq(published_at)
|
||||||
|
expect(topic.updated_at).to eq(published_at)
|
||||||
expect(topic.shared_draft).to be_blank
|
expect(topic.shared_draft).to be_blank
|
||||||
expect(UserHistory.where(
|
expect(UserHistory.where(
|
||||||
acting_user_id: moderator.id,
|
acting_user_id: moderator.id,
|
||||||
|
@ -40,6 +44,10 @@ describe TopicPublisher do
|
||||||
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
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue