0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-27 03:20:27 +01:00
discourse-custom-wizard/spec/extensions/topic_extension_spec.rb

43 Zeilen
1,4 KiB
Ruby

2023-09-18 23:36:21 +02:00
# frozen_string_literal: true
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) }
fab!(:user) { Fabricate(:user, refresh_auto_groups: true) }
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
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",
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",
),
)
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
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
)
end.not_to raise_error
2023-09-18 23:36:21 +02:00
end
end
end