From 892c15b64a8edf484ec19be9247d95772a6aa173 Mon Sep 17 00:00:00 2001 From: Rishabh Saxena Date: Thu, 10 Mar 2016 03:17:28 +0530 Subject: [PATCH 1/5] destroying purchased tickets. --- app/controllers/conference_registrations_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/conference_registrations_controller.rb b/app/controllers/conference_registrations_controller.rb index c9d7d216..007b9b74 100644 --- a/app/controllers/conference_registrations_controller.rb +++ b/app/controllers/conference_registrations_controller.rb @@ -85,7 +85,9 @@ class ConferenceRegistrationsController < ApplicationController end def destroy + tickets_purchased = TicketPurchase.find_by(conference_id: @registration.conference_id) if @registration.destroy + ticket_purchase.destroy redirect_to root_path, notice: "You are not registered for #{@conference.title} anymore!" else From 5ad99e1cd83f13d68469383ee924279d46d25219 Mon Sep 17 00:00:00 2001 From: Rishabh Saxena Date: Thu, 10 Mar 2016 03:18:24 +0530 Subject: [PATCH 2/5] fixed typo in destroying --- app/controllers/conference_registrations_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/conference_registrations_controller.rb b/app/controllers/conference_registrations_controller.rb index 007b9b74..d7d111ca 100644 --- a/app/controllers/conference_registrations_controller.rb +++ b/app/controllers/conference_registrations_controller.rb @@ -87,7 +87,7 @@ class ConferenceRegistrationsController < ApplicationController def destroy tickets_purchased = TicketPurchase.find_by(conference_id: @registration.conference_id) if @registration.destroy - ticket_purchase.destroy + tickets_purchased.destroy redirect_to root_path, notice: "You are not registered for #{@conference.title} anymore!" else From 5a19d47376d1241245a84ad609aa7f450038a855 Mon Sep 17 00:00:00 2001 From: Rishabh Saxena Date: Thu, 10 Mar 2016 03:20:15 +0530 Subject: [PATCH 3/5] checking if no tickets are purchased. passing tests. --- app/controllers/conference_registrations_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/conference_registrations_controller.rb b/app/controllers/conference_registrations_controller.rb index d7d111ca..34a1effd 100644 --- a/app/controllers/conference_registrations_controller.rb +++ b/app/controllers/conference_registrations_controller.rb @@ -87,7 +87,9 @@ class ConferenceRegistrationsController < ApplicationController def destroy tickets_purchased = TicketPurchase.find_by(conference_id: @registration.conference_id) if @registration.destroy - tickets_purchased.destroy + if tickets_purchased + tickets_purchased.destroy + end redirect_to root_path, notice: "You are not registered for #{@conference.title} anymore!" else From 297b1f8c8ae273ba5aaf0a7b019c49afd7b6d8d8 Mon Sep 17 00:00:00 2001 From: Rishabh Saxena Date: Thu, 10 Mar 2016 21:44:18 +0530 Subject: [PATCH 4/5] Adding tests for tickets deletion. --- spec/controllers/admin/registration_periods_controller_spec.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spec/controllers/admin/registration_periods_controller_spec.rb b/spec/controllers/admin/registration_periods_controller_spec.rb index 6daf08d8..ef6ffdba 100644 --- a/spec/controllers/admin/registration_periods_controller_spec.rb +++ b/spec/controllers/admin/registration_periods_controller_spec.rb @@ -145,6 +145,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 From ac066b0546f4b3549ce60345b0330eed01b83c87 Mon Sep 17 00:00:00 2001 From: Rishabh Saxena Date: Fri, 11 Mar 2016 14:59:44 +0530 Subject: [PATCH 5/5] deleting all associated tickets to a user --- app/controllers/conference_registrations_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/conference_registrations_controller.rb b/app/controllers/conference_registrations_controller.rb index 34a1effd..fd4a2938 100644 --- a/app/controllers/conference_registrations_controller.rb +++ b/app/controllers/conference_registrations_controller.rb @@ -85,7 +85,7 @@ class ConferenceRegistrationsController < ApplicationController end def destroy - tickets_purchased = TicketPurchase.find_by(conference_id: @registration.conference_id) + tickets_purchased = TicketPurchase.where(conference_id: @registration.conference_id) if @registration.destroy if tickets_purchased tickets_purchased.destroy