diff --git a/app/controllers/conference_registrations_controller.rb b/app/controllers/conference_registrations_controller.rb index c229440e..46cc2e38 100644 --- a/app/controllers/conference_registrations_controller.rb +++ b/app/controllers/conference_registrations_controller.rb @@ -83,7 +83,11 @@ class ConferenceRegistrationsController < ApplicationController end def destroy + tickets_purchased = TicketPurchase.where(conference_id: @registration.conference_id) if @registration.destroy + if tickets_purchased + tickets_purchased.destroy + end redirect_to root_path, notice: "You are not registered for #{@conference.title} anymore!" else diff --git a/spec/controllers/admin/registration_periods_controller_spec.rb b/spec/controllers/admin/registration_periods_controller_spec.rb index 6177fde7..5fe6d06b 100644 --- a/spec/controllers/admin/registration_periods_controller_spec.rb +++ b/spec/controllers/admin/registration_periods_controller_spec.rb @@ -144,6 +144,9 @@ describe Admin::RegistrationPeriodsController do it 'it deletes the registration period' do expect { delete :destroy, conference_id: conference.short_title }.to change(RegistrationPeriod, :count).by(-1) end + it 'it deletes the conference tickets' do + expect { delete :destroy, conference_id: conference.short_title }.to change(TicketPurchase, :count).by(-1) + end it 'redirects to users#show' do delete :destroy, conference_id: conference.short_title expect(response).to redirect_to admin_conference_registration_period_path