Merge pull request #1118 from rishabhs95/free-ticket
ability to create and purchase free tickets
This commit is contained in:
commit
a4ef10cf1b
9 changed files with 88 additions and 24 deletions
|
|
@ -1583,4 +1583,15 @@ describe Conference do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'after_create' do
|
||||
let(:conference) { Conference.new(title: 'ABC', short_title: 'XYZ', start_date: Date.today, end_date: Date.today + 10, timezone: 'GMT') }
|
||||
|
||||
it 'calls back to create free ticket' do
|
||||
conference.save
|
||||
conference.run_callbacks :create
|
||||
free_ticket = conference.tickets.first
|
||||
expect(free_ticket.price_cents).to eq(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -41,7 +41,21 @@ describe TicketPurchase do
|
|||
let!(:participant) { create(:user) }
|
||||
let!(:ticket_1) { create(:ticket) }
|
||||
let!(:ticket_2) { create(:ticket) }
|
||||
let!(:conference) { create(:conference, tickets: [ticket_1, ticket_2]) }
|
||||
let!(:free_ticket) { create(:ticket, price_cents: 0) }
|
||||
let!(:conference) { create(:conference, tickets: [ticket_1, ticket_2, free_ticket]) }
|
||||
|
||||
it 'creates purchase to free ticket' do
|
||||
tickets = { free_ticket.id.to_s => '10' }
|
||||
message = TicketPurchase.purchase(conference, participant, tickets)
|
||||
purchase = TicketPurchase.where(conference_id: conference.id,
|
||||
user_id: participant.id,
|
||||
ticket_id: free_ticket.id).first
|
||||
|
||||
expect(TicketPurchase.count).to eq(1)
|
||||
expect(purchase.quantity).to eq(10)
|
||||
expect(message.blank?).to be true
|
||||
|
||||
end
|
||||
|
||||
it 'creates a purchase for one ticket' do
|
||||
tickets = { ticket_1.id.to_s => '1' }
|
||||
|
|
|
|||
|
|
@ -22,14 +22,14 @@ describe Ticket do
|
|||
should validate_presence_of(:price_currency)
|
||||
end
|
||||
|
||||
it 'is not valid with a price_cents equals zero' do
|
||||
should_not allow_value(0).for(:price_cents)
|
||||
end
|
||||
|
||||
it 'is not valid with a price_cents smaller than zero' do
|
||||
should_not allow_value(-1).for(:price_cents)
|
||||
end
|
||||
|
||||
it 'is valid with a price_cents equals zero' do
|
||||
should allow_value(0).for(:price_cents)
|
||||
end
|
||||
|
||||
it 'is valid with a price_cents greater than zero' do
|
||||
should allow_value(1).for(:price_cents)
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue