2023-09-18 23:36:21 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-09-19 19:57:11 +02:00
|
|
|
describe Topic, type: :model do
|
2023-09-18 23:36:21 +02:00
|
|
|
fab!(:category_with_wizard) do
|
2024-10-16 13:52:03 +02:00
|
|
|
Fabricate(:category, custom_fields: { create_topic_wizard: "true" })
|
2023-09-18 23:36:21 +02:00
|
|
|
end
|
|
|
|
fab!(:category_without_wizard) { Fabricate(:category) }
|
2023-12-20 14:05:28 +01:00
|
|
|
fab!(:user) { Fabricate(:user, refresh_auto_groups: true) }
|
2023-09-19 19:57:11 +02:00
|
|
|
let(:valid_attrs) { Fabricate.attributes_for(:topic) }
|
2023-09-18 23:36:21 +02:00
|
|
|
|
2024-10-16 13:52:03 +02:00
|
|
|
context "with a create_topic_wizard custom field in the category" do
|
|
|
|
it "will not allow creating a topic directly" do
|
2023-09-19 19:57:11 +02:00
|
|
|
expect do
|
|
|
|
TopicCreator.create(
|
|
|
|
user,
|
|
|
|
Guardian.new(user),
|
|
|
|
valid_attrs.merge(
|
2024-10-16 13:52:03 +02:00
|
|
|
title: "A valid and sufficiently long title for testing",
|
2023-09-19 19:57:11 +02:00
|
|
|
category: category_with_wizard.id,
|
2024-10-16 13:52:03 +02:00
|
|
|
raw: "hello this is a test topic with category with custom fields",
|
|
|
|
),
|
2023-09-19 19:57:11 +02:00
|
|
|
)
|
2024-10-16 13:52:03 +02:00
|
|
|
end.to raise_error(Discourse::InvalidParameters, "Category not allowed for topic creation.")
|
2023-09-18 23:36:21 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-10-16 13:52:03 +02:00
|
|
|
context "without a create_topic_wizard custom field in the category" do
|
|
|
|
it "will allow creating a topic directly" do
|
2023-09-19 19:57:11 +02:00
|
|
|
expect do
|
|
|
|
TopicCreator.create(
|
|
|
|
user,
|
|
|
|
Guardian.new(user),
|
|
|
|
valid_attrs.merge(
|
|
|
|
category: category_without_wizard.id,
|
2024-10-16 13:52:03 +02:00
|
|
|
title: "Another valid and sufficiently long title for testing",
|
|
|
|
raw: "This is the body of a valid topic",
|
|
|
|
),
|
2023-09-18 23:36:21 +02:00
|
|
|
)
|
2023-09-19 19:57:11 +02:00
|
|
|
end.not_to raise_error
|
2023-09-18 23:36:21 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|