From b36d4e98e2e9fa0d0ce5c99b78686d1833b144c4 Mon Sep 17 00:00:00 2001 From: Rishabh Saxena Date: Fri, 19 Aug 2016 00:51:49 +0530 Subject: [PATCH] ticket_purchase_controller: free ticket routing --- app/controllers/ticket_purchases_controller.rb | 9 +++++++-- spec/features/ticket_purchases_spec.rb | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/controllers/ticket_purchases_controller.rb b/app/controllers/ticket_purchases_controller.rb index a8749eed..a1bf8826 100644 --- a/app/controllers/ticket_purchases_controller.rb +++ b/app/controllers/ticket_purchases_controller.rb @@ -11,8 +11,13 @@ class TicketPurchasesController < ApplicationController redirect_to new_conference_payment_path, notice: 'Please pay here to get tickets.' else - redirect_to conference_tickets_path(@conference.short_title), - error: 'Please get at least one ticket to continue.' + if current_user.ticket_purchases.by_conference(@conference).paid.any? + redirect_to conference_conference_registration_path(@conference.short_title), + notice: 'You have free tickets for the conference.' + else + redirect_to conference_tickets_path(@conference.short_title), + error: 'Please get at least one ticket to continue.' + end end else redirect_to conference_conference_registration_path(@conference.short_title), diff --git a/spec/features/ticket_purchases_spec.rb b/spec/features/ticket_purchases_spec.rb index ad8bca54..f8c755a3 100644 --- a/spec/features/ticket_purchases_spec.rb +++ b/spec/features/ticket_purchases_spec.rb @@ -101,10 +101,10 @@ feature Registration do click_button 'Continue' - expect(current_path).to eq(new_conference_conference_registration_path(conference.short_title)) + expect(current_path).to eq(conference_conference_registration_path(conference.short_title)) purchase = TicketPurchase.where(user_id: participant.id, ticket_id: free_ticket.id).first expect(purchase.quantity).to eq(5) - expect(purchase.paid).to eq(true) + expect(purchase.paid).to be true expect(page.has_content?("5 #{free_ticket.title} Tickets for $ 0")).to be true end