diff --git a/app/controllers/payments_controller.rb b/app/controllers/payments_controller.rb index d2317bbc..ab05aed3 100644 --- a/app/controllers/payments_controller.rb +++ b/app/controllers/payments_controller.rb @@ -34,8 +34,6 @@ class PaymentsController < ApplicationController redirect_to conference_physical_tickets_path, notice: 'Thanks! Your ticket is booked successfully.' end - - @has_registration_ticket = nil else @total_amount_to_pay = Ticket.total_price(@conference, current_user, paid: false) @unpaid_ticket_purchases = current_user.ticket_purchases.unpaid.by_conference(@conference) diff --git a/app/controllers/ticket_purchases_controller.rb b/app/controllers/ticket_purchases_controller.rb index 58e32feb..3034d742 100644 --- a/app/controllers/ticket_purchases_controller.rb +++ b/app/controllers/ticket_purchases_controller.rb @@ -31,14 +31,14 @@ class TicketPurchasesController < ApplicationController # User needs to pay for tickets if any of them is not free. if current_user.ticket_purchases.by_conference(@conference).unpaid.any? - has_registration_ticket = count_registration_tickets_before == 0 && count_registration_tickets_after == 1 + has_registration_ticket = count_registration_tickets_before.zero? && count_registration_tickets_after == 1 redirect_to new_conference_payment_path(has_registration_ticket: has_registration_ticket), notice: 'Please pay here to get tickets.' return end # Redirect to registration page for a user who didn't have a registration ticket and is purchasing one - if count_registration_tickets_before == 0 && count_registration_tickets_after == 1 + if count_registration_tickets_before.zero? && count_registration_tickets_after == 1 redirect_to new_conference_conference_registration_path(@conference.short_title), notice: 'Thanks! Your ticket is booked successfully. Please register for the conference.' else diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index b1a9de71..48eb7e8e 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -441,6 +441,17 @@ describe User do end end end + + describe '#count_registration_tickets' do + let(:registration_ticket) { create(:registration_ticket, price_cents: 0) } + let(:conference3) { create(:conference, short_title: 'oSC17', title: 'openSUSE Conference 2017', tickets: [registration_ticket]) } + let(:ticket_purchase) { create(user: user, conference: conference3, ticket: registration_ticket, quantity: 1) } + + it 'counts the number of registration tickets of a conference held by user' do + expect(user.count_registration_tickets(conference3).eq(1)) + expect(user.count_registration_tickets(conference2).eq(0)) + end + end end describe 'rolify' do