mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-13 19:54:02 +00:00
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)
|
||||
end
|
||||
|
||||
def paid?(user)
|
||||
ticket_purchases.paid.by_user(user).present?
|
||||
def tickets_paid(user)
|
||||
paid_tickets = quantity_bought_by(user, paid: true)
|
||||
unpaid_tickets = quantity_bought_by(user, paid: false)
|
||||
"#{paid_tickets}/#{paid_tickets+unpaid_tickets}"
|
||||
end
|
||||
|
||||
def quantity_bought_by(user, paid: false)
|
||||
|
|
|
|||
|
|
@ -33,5 +33,5 @@
|
|||
%td
|
||||
= buyer.affiliation
|
||||
%td
|
||||
= @ticket.paid?(buyer)
|
||||
= @ticket.tickets_paid(buyer)
|
||||
|
||||
|
|
|
|||
|
|
@ -64,24 +64,6 @@ describe Ticket do
|
|||
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
|
||||
let!(:ticket_purchase) { create(:ticket_purchase, user: user, ticket: ticket) }
|
||||
|
||||
|
|
@ -101,6 +83,17 @@ describe Ticket do
|
|||
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
|
||||
context 'user has not paid' 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