[test] Fix style; add test for user#count_registration_tickets
This commit is contained in:
parent
6e3cdc2614
commit
11a4d200f7
3 changed files with 13 additions and 4 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue