diff --git a/app/controllers/custom_wizard/admin/wizard.rb b/app/controllers/custom_wizard/admin/wizard.rb index 08e7b6d0..6737da6c 100644 --- a/app/controllers/custom_wizard/admin/wizard.rb +++ b/app/controllers/custom_wizard/admin/wizard.rb @@ -26,6 +26,8 @@ class CustomWizard::AdminWizardController < CustomWizard::AdminController def remove if CustomWizard::Template.remove(@wizard.id) + related_custom_fields = CategoryCustomField.where(name: 'create_topic_wizard', value: @wizard.name) + related_custom_fields.destroy_all render json: success_json else render json: failed_json diff --git a/spec/requests/custom_wizard/admin/wizard_controller_spec.rb b/spec/requests/custom_wizard/admin/wizard_controller_spec.rb index 3ee46f2a..cf1b7ec7 100644 --- a/spec/requests/custom_wizard/admin/wizard_controller_spec.rb +++ b/spec/requests/custom_wizard/admin/wizard_controller_spec.rb @@ -5,7 +5,7 @@ describe CustomWizard::AdminWizardController do fab!(:user1) { Fabricate(:user) } fab!(:user2) { Fabricate(:user) } let(:template) { get_wizard_fixture("wizard") } - let(:category) { Fabricate(:category, custom_fields: { create_topic_wizard: "wizard" }) } + let(:category) { Fabricate(:category, custom_fields: { create_topic_wizard: template['name'] }) } before do CustomWizard::Template.save(template, skip_jobs: true) @@ -40,12 +40,12 @@ describe CustomWizard::AdminWizardController do expect(response.parsed_body['steps'].length).to eq(3) end - it "removes wizard templates" do - expect(CategoryCustomField.find_by(category_id: category.id, name: 'create_topic_wizard')).not_to eq(nil) + it "removes wizard templates and make sure create_topic_wizard settings for that wizard are removed from Categories" do + expect(CategoryCustomField.find_by(category_id: category.id, name: 'create_topic_wizard', value: template['name'])).not_to eq(nil) delete "/admin/wizards/wizard/#{template['id']}.json" expect(response.status).to eq(200) expect(CustomWizard::Template.exists?(template['id'])).to eq(false) - expect(CategoryCustomField.find_by(category_id: category.id, name: 'create_topic_wizard')).to eq(nil) + expect(CategoryCustomField.find_by(name: 'create_topic_wizard', value: template['name'])).to eq(nil) end it "saves wizard templates" do