diff --git a/plugin.rb b/plugin.rb index 497a1461..3a84371b 100644 --- a/plugin.rb +++ b/plugin.rb @@ -239,10 +239,11 @@ after_initialize do on(:before_create_topic) do |topic_params, user| category = topic_params.category - if category&.custom_fields&.[]('create_topic_wizard').present? + wizard_submission_id = topic_params.custom_fields&.[]('wizard_submission_id') + if category&.custom_fields&.[]('create_topic_wizard').present? && wizard_submission_id.blank? raise Discourse::InvalidParameters.new( - I18n.t('wizard.error_messages.wizard_replacing_composer') - ) + I18n.t('wizard.error_messages.wizard_replacing_composer') + ) end end end diff --git a/spec/components/custom_wizard/action_spec.rb b/spec/components/custom_wizard/action_spec.rb index c450582d..57fe7f56 100644 --- a/spec/components/custom_wizard/action_spec.rb +++ b/spec/components/custom_wizard/action_spec.rb @@ -450,4 +450,29 @@ describe CustomWizard::Action do expect(action.result.success?).to eq(true) expect(Topic.find(action.result.output).custom_fields["topic_custom_field"]).to eq("t") end + + context 'creating a topic when there are multiple actions' do + it 'works' do + wizard_template['actions'] << create_topic + wizard_template['actions'] << send_message + update_template(wizard_template) + wizard = CustomWizard::Builder.new(@template[:id], user).build + wizard.create_updater( + wizard.steps.first.id, + step_1_field_1: 'Topic Title', + step_1_field_2: 'topic body' + ).update + wizard.create_updater(wizard.steps.second.id, {}).update + wizard.create_updater(wizard.steps.last.id, step_3_field_3: category.id) + .update + User.create(username: 'angus1', email: 'angus1@email.com') + wizard.create_updater(wizard.steps[0].id, {}).update + wizard.create_updater(wizard.steps[1].id, {}).update + topic = Topic.where(title: 'Topic Title', category_id: category.id) + expect(topic.exists?).to eq(true) + expect( + Post.where(topic_id: topic.pluck(:id), raw: 'topic body').exists? + ).to eq(true) + end + end end diff --git a/spec/serializers/custom_wizard/submission_serializer_spec.rb b/spec/serializers/custom_wizard/submission_serializer_spec.rb index d81cfb15..fc2c46a2 100644 --- a/spec/serializers/custom_wizard/submission_serializer_spec.rb +++ b/spec/serializers/custom_wizard/submission_serializer_spec.rb @@ -24,7 +24,7 @@ describe CustomWizard::SubmissionSerializer do it 'should return submission attributes' do wizard = CustomWizard::Wizard.create(template_json["id"]) - list = CustomWizard::Submission.list(wizard, page: 0) + list = CustomWizard::Submission.list(wizard, page: 0, order_by: 'id') json_array = ActiveModel::ArraySerializer.new( list.submissions,