2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-13 15:59:12 -04:00
|
|
|
require "topic_publisher"
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
RSpec.describe TopicPublisher do
|
|
|
|
describe "shared drafts" do
|
2019-05-06 23:12:20 -04:00
|
|
|
fab!(:shared_drafts_category) { Fabricate(:category) }
|
|
|
|
fab!(:category) { Fabricate(:category) }
|
2018-03-13 15:59:12 -04:00
|
|
|
|
|
|
|
before { SiteSetting.shared_drafts_category = shared_drafts_category.id }
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
context "when publishing" do
|
2019-05-06 23:12:20 -04:00
|
|
|
fab!(:topic) { Fabricate(:topic, category: shared_drafts_category, visible: false) }
|
|
|
|
fab!(:shared_draft) { Fabricate(:shared_draft, topic: topic, category: category) }
|
|
|
|
fab!(:moderator) { Fabricate(:moderator) }
|
|
|
|
fab!(:op) { Fabricate(:post, topic: topic) }
|
2022-07-20 12:07:18 -04:00
|
|
|
fab!(:user) { Fabricate(:user) }
|
|
|
|
fab!(:tag) { Fabricate(:tag) }
|
2018-03-13 15:59:12 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
# Create a revision
|
|
|
|
op.set_owner(Fabricate(:coding_horror), Discourse.system_user)
|
|
|
|
op.reload
|
|
|
|
end
|
|
|
|
|
|
|
|
it "will publish the topic properly" do
|
2018-03-26 16:06:20 -04:00
|
|
|
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
|
2020-03-10 17:13:17 -04:00
|
|
|
expect(topic.created_at).to eq_time(published_at)
|
|
|
|
expect(topic.updated_at).to eq_time(published_at)
|
2018-03-26 16:06:20 -04:00
|
|
|
expect(topic.shared_draft).to be_blank
|
2019-04-16 02:09:51 -04:00
|
|
|
|
2018-03-26 16:06:20 -04:00
|
|
|
expect(
|
|
|
|
UserHistory.where(
|
|
|
|
acting_user_id: moderator.id,
|
|
|
|
action: UserHistory.actions[:topic_published],
|
2023-01-09 06:18:21 -05:00
|
|
|
),
|
2018-03-26 16:06:20 -04:00
|
|
|
).to be_present
|
2019-04-16 02:09:51 -04:00
|
|
|
|
2018-03-26 16:06:20 -04:00
|
|
|
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)
|
2020-03-10 17:13:17 -04:00
|
|
|
expect(op.created_at).to eq_time(published_at)
|
|
|
|
expect(op.updated_at).to eq_time(published_at)
|
|
|
|
expect(op.last_version_at).to eq_time(published_at)
|
2018-03-26 16:06:20 -04:00
|
|
|
end
|
2018-03-13 15:59:12 -04:00
|
|
|
end
|
2022-07-20 12:07:18 -04:00
|
|
|
|
|
|
|
it "will notify users watching tag" do
|
|
|
|
Jobs.run_immediately!
|
|
|
|
|
|
|
|
TagUser.create!(
|
|
|
|
user_id: user.id,
|
|
|
|
tag_id: tag.id,
|
|
|
|
notification_level: NotificationLevels.topic_levels[:watching],
|
|
|
|
)
|
|
|
|
|
|
|
|
topic.update!(tags: [tag])
|
|
|
|
|
|
|
|
expect {
|
|
|
|
TopicPublisher.new(topic, moderator, shared_draft.category_id).publish!
|
|
|
|
}.to change { Notification.count }.by(1)
|
|
|
|
|
|
|
|
topic.reload
|
|
|
|
expect(topic.tags).to contain_exactly(tag)
|
|
|
|
end
|
2018-03-13 15:59:12 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|