Display paid and unpaid tickets in admin/tickets#show
This commit is contained in:
parent
c552d08b8e
commit
d974807134
3 changed files with 16 additions and 21 deletions
|
|
@ -19,8 +19,10 @@ class Ticket < ActiveRecord::Base
|
||||||
buyers.include?(user)
|
buyers.include?(user)
|
||||||
end
|
end
|
||||||
|
|
||||||
def paid?(user)
|
def tickets_paid(user)
|
||||||
ticket_purchases.paid.by_user(user).present?
|
paid_tickets = quantity_bought_by(user, paid: true)
|
||||||
|
unpaid_tickets = quantity_bought_by(user, paid: false)
|
||||||
|
"#{paid_tickets}/#{paid_tickets+unpaid_tickets}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def quantity_bought_by(user, paid: false)
|
def quantity_bought_by(user, paid: false)
|
||||||
|
|
|
||||||
|
|
@ -33,5 +33,5 @@
|
||||||
%td
|
%td
|
||||||
= buyer.affiliation
|
= buyer.affiliation
|
||||||
%td
|
%td
|
||||||
= @ticket.paid?(buyer)
|
= @ticket.tickets_paid(buyer)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -64,24 +64,6 @@ describe Ticket do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#paid?' do
|
|
||||||
let!(:ticket_purchase) { create(:ticket_purchase, user: user, ticket: ticket) }
|
|
||||||
|
|
||||||
context 'user has paid' do
|
|
||||||
before { ticket_purchase.update_attributes(paid: true) }
|
|
||||||
|
|
||||||
it 'returns true' do
|
|
||||||
expect(ticket.paid?(user)).to eq(true)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'user has not paid' do
|
|
||||||
it 'returns false' do
|
|
||||||
expect(ticket.paid?(user)).to eq(false)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe '#unpaid?' do
|
describe '#unpaid?' do
|
||||||
let!(:ticket_purchase) { create(:ticket_purchase, user: user, ticket: ticket) }
|
let!(:ticket_purchase) { create(:ticket_purchase, user: user, ticket: ticket) }
|
||||||
|
|
||||||
|
|
@ -101,6 +83,17 @@ describe Ticket do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#tickets_paid' do
|
||||||
|
before do
|
||||||
|
create(:ticket_purchase, user: user, ticket: ticket)
|
||||||
|
create(:ticket_purchase, user: user, ticket: ticket, paid: true)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns correct number of paid/total tickets' do
|
||||||
|
expect(ticket.tickets_paid(user)).to eq('10/20')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe '#quantity_bought_by' do
|
describe '#quantity_bought_by' do
|
||||||
context 'user has not paid' do
|
context 'user has not paid' do
|
||||||
it 'returns the correct value if the user has bought this ticket' do
|
it 'returns the correct value if the user has bought this ticket' do
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue