From d4a28610519d86e15944b942f163cf7c49481c56 Mon Sep 17 00:00:00 2001 From: Michael Ball Date: Tue, 23 Feb 2021 18:17:45 -0800 Subject: [PATCH] Improve Registration Flow Some: * Trying to register when a ticket is required will now redirect you to buy tickets. * #64 will then redirect you back to complete the registration --- app/controllers/conference_registrations_controller.rb | 3 +++ app/models/registration.rb | 3 ++- spec/features/ticket_purchases_spec.rb | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/controllers/conference_registrations_controller.rb b/app/controllers/conference_registrations_controller.rb index 9ee6e6ae..fd6dd14c 100644 --- a/app/controllers/conference_registrations_controller.rb +++ b/app/controllers/conference_registrations_controller.rb @@ -64,6 +64,9 @@ class ConferenceRegistrationsController < ApplicationController redirect_to conference_conference_registration_path(@conference.short_title), notice: 'You are now registered and will be receiving E-Mail notifications.' end + elsif @conference.registration_ticket_required? && !current_user.supports?(@conference) + redirect_to conference_tickets_path(@conference.short_title), + error: 'You must buy a registration ticket before registering.' else flash.now[:error] = "Could not create your registration for #{@conference.title}: "\ "#{@registration.errors.full_messages.join('. ')}." diff --git a/app/models/registration.rb b/app/models/registration.rb index 6fd64a1d..944d0e65 100644 --- a/app/models/registration.rb +++ b/app/models/registration.rb @@ -84,7 +84,8 @@ class Registration < ApplicationRecord end def user_has_registration_ticket - return if TicketPurchase.where(user: user, ticket: conference.registration_tickets).paid.any? + return if conference.registration_ticket_required? && + TicketPurchase.where(user: user, ticket: conference.registration_tickets).paid.any? errors.add(:base, 'You must purchase a registration ticket before registering') if TicketPurchase.where(user: user, ticket: conference.registration_tickets).unpaid.any? diff --git a/spec/features/ticket_purchases_spec.rb b/spec/features/ticket_purchases_spec.rb index d67f0b68..7d6f49ca 100644 --- a/spec/features/ticket_purchases_spec.rb +++ b/spec/features/ticket_purchases_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -feature Registration do +feature Registration, feature: true, js: true do let!(:ticket) { create(:ticket) } let!(:free_ticket) { create(:ticket, price_cents: 0) } let!(:first_registration_ticket) { create(:registration_ticket, price_cents: 0) } @@ -146,7 +146,7 @@ feature Registration do context 'who is registered' do - scenario 'unregisters from conference, but ticket purchases dont delete', feature: true, js: true do + scenario 'unregisters from conference, but ticket purchases dont delete' do visit root_path click_link 'Register'