add more tests

This commit is contained in:
Rishabh Saxena 2016-07-06 12:40:42 +05:30
parent c0c84b9dbf
commit 38ae24c6b3
6 changed files with 157 additions and 9 deletions

View file

@ -82,17 +82,37 @@ describe Ticket do
end
end
describe '#unpaid?' do
let!(:ticket_purchase) { create(:ticket_purchase, user: user, ticket: ticket) }
context 'user has not paid' do
before { ticket_purchase.update_attributes(paid: false) }
it 'returns true' do
expect(ticket.unpaid?(user)).to eq(true)
end
end
context 'user has paid' do
before { ticket_purchase.update_attributes(paid: true) }
it 'returns false' do
expect(ticket.unpaid?(user)).to eq(false)
end
end
end
describe '#quantity_bought_by' do
it 'returns the correct value if the user has bought this ticket' do
create(:ticket_purchase,
user: user,
ticket: ticket,
quantity: 20)
expect(ticket.quantity_bought_by(user, 'f')).to eq(20)
expect(ticket.quantity_bought_by(user, false)).to eq(20)
end
it 'returns zero if the user has not bought this ticket' do
expect(ticket.quantity_bought_by(user, 'f')).to eq(0)
expect(ticket.quantity_bought_by(user, false)).to eq(0)
end
end
@ -102,11 +122,11 @@ describe Ticket do
user: user,
ticket: ticket,
quantity: 20)
expect(ticket.total_price(user, 'f')).to eq(Money.new(100000, 'USD'))
expect(ticket.total_price(user, false)).to eq(Money.new(100000, 'USD'))
end
it 'returns zero if the user has not bought this ticket' do
expect(ticket.total_price(user, 'f')).to eq(Money.new(0, 'USD'))
expect(ticket.total_price(user, false)).to eq(Money.new(0, 'USD'))
end
end
@ -116,7 +136,7 @@ describe Ticket do
describe 'user has bought' do
context 'no tickets' do
it 'returns zero' do
expect(Ticket.total_price(conference, user, 'f')).to eq(Money.new(0, 'USD'))
expect(Ticket.total_price(conference, user, false)).to eq(Money.new(0, 'USD'))
end
end
@ -126,7 +146,7 @@ describe Ticket do
end
it 'returns the correct total price' do
expect(Ticket.total_price(conference, user, 'f')).to eq(Money.new(100000, 'USD'))
expect(Ticket.total_price(conference, user, false)).to eq(Money.new(100000, 'USD'))
end
end
@ -138,7 +158,7 @@ describe Ticket do
it 'returns the correct total price' do
total_price = Money.new(200000, 'USD')
expect(Ticket.total_price(conference, user, 'f')).to eq(total_price)
expect(Ticket.total_price(conference, user, false)).to eq(total_price)
end
end
end