modify tests

This commit is contained in:
Rishabh Saxena 2016-07-14 19:09:39 +05:30
parent a3d709bc75
commit 9b704e483e
2 changed files with 33 additions and 33 deletions

View file

@ -39,8 +39,24 @@ describe Payment do
let!(:participant) { create(:user) } let!(:participant) { create(:user) }
let!(:ticket_1) { create(:ticket) } let!(:ticket_1) { create(:ticket) }
let!(:conference) { create(:conference, tickets: [ticket_1]) } let!(:conference) { create(:conference, tickets: [ticket_1]) }
let!(:payment) { create(:payment) }
it 'creates no ticket purchase or payment if amount is less than 1' do
tickets = { ticket_1.id.to_s => '-1' }
TicketPurchase.purchase(conference, participant, tickets)
expect(TicketPurchase.count).to eq(0)
expect(Payment.count).to eq(0)
end
it 'creates no ticket purchase or payment if amount is 0' do
tickets = { ticket_1.id.to_s => '0' }
TicketPurchase.purchase(conference, participant, tickets)
expect(TicketPurchase.count).to eq(0)
expect(Payment.count).to eq(0)
end
let(:payment) { create(:payment) }
it 'creates a purchase and payment for one ticket' do it 'creates a purchase and payment for one ticket' do
tickets = { ticket_1.id.to_s => '1' } tickets = { ticket_1.id.to_s => '1' }
message = TicketPurchase.purchase(conference, participant, tickets) message = TicketPurchase.purchase(conference, participant, tickets)
@ -49,29 +65,14 @@ describe Payment do
ticket_id: ticket_1.id).first ticket_id: ticket_1.id).first
expect(TicketPurchase.count).to eq(1) expect(TicketPurchase.count).to eq(1)
expect(purchase.quantity).to eq(1) # expect(purchase.quantity).to eq(1)
expect(message.blank?).to be true expect(message.blank?).to be true
response = Payment.make_payment(participant, conference, 1000, payment) payment = Payment.new
new_payment = Payment.first payment.purchase(participant, conference, 1000)
expect(Payment.count).to eq(1) expect(Payment.count).to eq(1)
expect(new_payment.amount).to eq(10) expect(payment.blank?).to be true
expect(response.blank?).to be true
end
it 'creates no ticket purchase or payment if amount is less than 1' do
tickets = { ticket_1.id.to_s => '-1' }
TicketPurchase.purchase(conference, participant, tickets)
expect(TicketPurchase.count).to eq(0)
end
it 'creates no ticket purchase or payment if amount is 0' do
tickets = { ticket_1.id.to_s => '0' }
TicketPurchase.purchase(conference, participant, tickets)
expect(TicketPurchase.count).to eq(0)
end end
end end
end end

View file

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