delete unused methods, add feature tests

This commit is contained in:
Rishabh Saxena 2016-07-15 02:46:31 +05:30
parent 3b4c7d70c0
commit 223a0eead9
7 changed files with 165 additions and 47 deletions

View file

@ -102,30 +102,52 @@ describe Ticket do
end
describe '#quantity_bought_by' do
it 'returns 0 if the user has bought but not paid for this ticket' do
create(:ticket_purchase,
user: user,
ticket: ticket,
quantity: 20)
expect(ticket.quantity_bought_by(user, paid: false)).to eq(0)
context 'user has not paid' 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, paid: false)).to eq(20)
end
it 'returns zero if the user has not bought this ticket' do
expect(ticket.quantity_bought_by(user, paid: false)).to eq(0)
end
end
it 'returns zero if the user has not bought this ticket' do
expect(ticket.quantity_bought_by(user, paid: false)).to eq(0)
context 'user has paid' do
let!(:ticket_purchase) { create(:ticket_purchase, user: user, ticket: ticket, quantity: 20) }
before { ticket_purchase.update_attributes(paid: true) }
it 'returns the correct value if the user has bought and paid for this ticket' do
expect(ticket.quantity_bought_by(user, paid: true)).to eq(20)
end
end
end
describe '#total_price' do
it 'returns the 0 if the user has bought but not paid for this ticket' do
create(:ticket_purchase,
user: user,
ticket: ticket,
quantity: 20)
expect(ticket.total_price(user, paid: false)).to eq(Money.new(0, 'USD'))
context 'user has not paid' 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.total_price(user, paid: 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, paid: false)).to eq(Money.new(0, 'USD'))
end
end
it 'returns zero if the user has not bought this ticket' do
expect(ticket.total_price(user, paid: false)).to eq(Money.new(0, 'USD'))
context 'user has paid' do
let!(:ticket_purchase) { create(:ticket_purchase, user: user, ticket: ticket, quantity: 20) }
before { ticket_purchase.update_attributes(paid: true) }
it 'returns the correct value if the user has bought this ticket' do
expect(ticket.total_price(user, paid: true)).to eq(Money.new(100000, 'USD'))
end
end
end
@ -144,8 +166,8 @@ describe Ticket do
create(:ticket_purchase, ticket: ticket, user: user, quantity: 20)
end
it 'returns 0 as total price unless paid' do
expect(Ticket.total_price(conference, user, paid: false)).to eq(Money.new(0, 'USD'))
it 'returns the correct total price' do
expect(Ticket.total_price(conference, user, paid: false)).to eq(Money.new(100000, 'USD'))
end
end
@ -155,8 +177,8 @@ describe Ticket do
create(:ticket_purchase, ticket: diversity_supporter_ticket, user: user, quantity: 2)
end
it 'returns 0 as total price unless paid' do
total_price = Money.new(0, 'USD')
it 'returns the correct total price' do
total_price = Money.new(200000, 'USD')
expect(Ticket.total_price(conference, user, paid: false)).to eq(total_price)
end
end