0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-12-04 22:31:09 +01:00
discourse-custom-wizard/spec/extensions/topic_extension_spec.rb

46 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
Fabricate(:category, custom_fields: { create_topic_wizard: 'true' })
end
fab!(:category_without_wizard) { Fabricate(:category) }
fab!(:user) { Fabricate(:user) }
let(:valid_attrs) { Fabricate.attributes_for(:topic) }
2023-09-18 23:36:21 +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(
title: 'A valid and sufficiently long title for testing',
category: category_with_wizard.id,
raw: 'hello this is a test topic with category with custom fields'
)
)
end.to raise_error(
Discourse::InvalidParameters,
'Category not allowed for topic creation.'
2023-09-18 23:36:21 +02:00
)
end
end
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,
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