From 29d7818a4a4b5fdfd6245b7cfbd91d24d0bb028c Mon Sep 17 00:00:00 2001 From: jumagura Date: Mon, 18 Sep 2023 17:36:21 -0400 Subject: [PATCH] DEV: Add spec for validation --- spec/extensions/topic_extension_spec.rb | 37 +++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 spec/extensions/topic_extension_spec.rb diff --git a/spec/extensions/topic_extension_spec.rb b/spec/extensions/topic_extension_spec.rb new file mode 100644 index 00000000..e4fabfea --- /dev/null +++ b/spec/extensions/topic_extension_spec.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +class DummyTopic < Topic + include CustomWizardTopicExtension +end + +describe DummyTopic, type: :model do + fab!(:category_with_wizard) do + Fabricate(:category, custom_fields: { create_topic_wizard: 'true' }) + end + fab!(:category_without_wizard) { Fabricate(:category) } + fab!(:user) { Fabricate(:user) } + + context 'when the category has a create_topic_wizard custom field' do + it 'does not allow creating a topic directly' do + topic = DummyTopic.new(user: user, category: category_with_wizard) + topic.valid? + expect(topic.errors[:base]).to include( + I18n.t('wizard.error_messages.wizard_replacing_composer') + ) + end + end + + context 'when the category does not have a create_topic_wizard custom field' do + it 'allows creating a topic directly' do + topic = + DummyTopic.new( + user: user, + category: category_without_wizard, + title: 'A valid topic title' + ) + is_valid = topic.valid? + puts topic.errors.full_messages unless is_valid + expect(is_valid).to be_truthy + end + end +end