mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 08:32:26 +08:00
6e161d3e75
The most common thing that we do with fab! is: fab!(:thing) { Fabricate(:thing) } This commit adds a shorthand for this which is just simply: fab!(:thing) i.e. If you omit the block, then, by default, you'll get a `Fabricate`d object using the fabricator of the same name.
78 lines
2.3 KiB
Ruby
78 lines
2.3 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "topic_publisher"
|
|
|
|
RSpec.describe TopicPublisher do
|
|
describe "shared drafts" do
|
|
fab!(:shared_drafts_category) { Fabricate(:category) }
|
|
fab!(:category)
|
|
|
|
before { SiteSetting.shared_drafts_category = shared_drafts_category.id }
|
|
|
|
context "when publishing" do
|
|
fab!(:topic) { Fabricate(:topic, category: shared_drafts_category, visible: false) }
|
|
fab!(:shared_draft) { Fabricate(:shared_draft, topic: topic, category: category) }
|
|
fab!(:moderator)
|
|
fab!(:op) { Fabricate(:post, topic: topic) }
|
|
fab!(:user)
|
|
fab!(:tag)
|
|
|
|
before do
|
|
# Create a revision
|
|
op.set_owner(Fabricate(:coding_horror), Discourse.system_user)
|
|
op.reload
|
|
end
|
|
|
|
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!
|
|
|
|
topic.reload
|
|
expect(topic.category).to eq(category)
|
|
expect(topic).to be_visible
|
|
expect(topic.created_at).to eq_time(published_at)
|
|
expect(topic.updated_at).to eq_time(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_time(published_at)
|
|
expect(op.updated_at).to eq_time(published_at)
|
|
expect(op.last_version_at).to eq_time(published_at)
|
|
end
|
|
end
|
|
|
|
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
|
|
end
|
|
end
|
|
end
|