1) Topic with a create_topic_wizard custom field in the category will not allow creating a topic directly
Failure/Error:
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'
)
)
expected Discourse::InvalidParameters with "Category not allowed for topic creation.", got #<Discourse::InvalidAccess: can_create? failed> with backtrace:
# ./lib/guardian/ensure_magic.rb:11:in `method_missing'
# ./lib/topic_creator.rb:143:in `setup_topic_params'
# ./lib/topic_creator.rb:45:in `create'
# ./lib/topic_creator.rb:9:in `create'
# ./plugins/discourse-custom-wizard/spec/extensions/topic_extension_spec.rb:14:in `block (4 levels) in <main>'
# ./plugins/discourse-custom-wizard/spec/extensions/topic_extension_spec.rb:13:in `block (3 levels) in <main>'
# ./spec/rails_helper.rb:491:in `block (3 levels) in <top (required)>'
# ./spec/rails_helper.rb:486:in `block (2 levels) in <top (required)>'
# ./spec/rails_helper.rb:475:in `block (2 levels) in <top (required)>'
# ./plugins/discourse-custom-wizard/spec/extensions/topic_extension_spec.rb:13:in `block (3 levels) in <main>'
# ./spec/rails_helper.rb:491:in `block (3 levels) in <top (required)>'
# ./spec/rails_helper.rb:486:in `block (2 levels) in <top (required)>'
# ./spec/rails_helper.rb:475:in `block (2 levels) in <top (required)>'
2) Topic without a create_topic_wizard custom field in the category will allow creating a topic directly
Failure/Error:
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'
)
)
expected no Exception, got #<Discourse::InvalidAccess: can_create? failed> with backtrace:
# ./lib/guardian/ensure_magic.rb:11:in `method_missing'
# ./lib/topic_creator.rb:143:in `setup_topic_params'
# ./lib/topic_creator.rb:45:in `create'
# ./lib/topic_creator.rb:9:in `create'
# ./plugins/discourse-custom-wizard/spec/extensions/topic_extension_spec.rb:33:in `block (4 levels) in <main>'
# ./plugins/discourse-custom-wizard/spec/extensions/topic_extension_spec.rb:32:in `block (3 levels) in <main>'
# ./spec/rails_helper.rb:491:in `block (3 levels) in <top (required)>'
# ./spec/rails_helper.rb:486:in `block (2 levels) in <top (required)>'
# ./spec/rails_helper.rb:475:in `block (2 levels) in <top (required)>'
# ./plugins/discourse-custom-wizard/spec/extensions/topic_extension_spec.rb:32:in `block (3 levels) in <main>'
# ./spec/rails_helper.rb:491:in `block (3 levels) in <top (required)>'
# ./spec/rails_helper.rb:486:in `block (2 levels) in <top (required)>'
# ./spec/rails_helper.rb:475:in `block (2 levels) in <top (required)>'