mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-13 19:54:02 +00:00
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
|
|
@ -2,7 +2,8 @@ require 'spec_helper'
|
|||
|
||||
feature Registration do
|
||||
let!(:ticket) { create(:ticket) }
|
||||
let!(:conference) { create(:conference, title: 'ExampleCon', tickets: [ticket], registration_period: create(:registration_period, start_date: 3.days.ago)) }
|
||||
let!(:free_ticket) { create(:ticket, price_cents: 0) }
|
||||
let!(:conference) { create(:conference, title: 'ExampleCon', tickets: [ticket, free_ticket], registration_period: create(:registration_period, start_date: 3.days.ago)) }
|
||||
let!(:participant) { create(:user) }
|
||||
|
||||
context 'as a participant' do
|
||||
|
|
@ -87,6 +88,26 @@ feature Registration do
|
|||
expect(flash).to eq('Your card was declined. Please try again with correct credentials.')
|
||||
end
|
||||
end
|
||||
|
||||
scenario 'purchases free tickets' do
|
||||
visit root_path
|
||||
click_link 'Register'
|
||||
|
||||
expect(current_path).to eq(new_conference_conference_registration_path(conference.short_title))
|
||||
click_button 'Register'
|
||||
|
||||
fill_in "tickets__#{free_ticket.id}", with: '5'
|
||||
expect(current_path).to eq(conference_tickets_path(conference.short_title))
|
||||
|
||||
click_button 'Continue'
|
||||
|
||||
expect(current_path).to eq(conference_conference_registration_path(conference.short_title))
|
||||
purchase = TicketPurchase.where(user_id: participant.id, ticket_id: free_ticket.id).first
|
||||
expect(purchase.quantity).to eq(5)
|
||||
expect(purchase.paid).to be true
|
||||
|
||||
expect(page.has_content?("5 #{free_ticket.title} Tickets for $ 0")).to be true
|
||||
end
|
||||
end
|
||||
|
||||
context 'who is registered' do
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ feature Ticket do
|
|||
|
||||
click_button 'Create Ticket'
|
||||
expect(flash).to eq('Ticket successfully created.')
|
||||
expect(Ticket.count).to eq(1)
|
||||
expect(Ticket.count).to eq(2)
|
||||
end
|
||||
|
||||
scenario 'add a invalid ticket', feature: true, js: true do
|
||||
|
|
@ -35,8 +35,8 @@ feature Ticket do
|
|||
fill_in 'ticket_price', with: '-1'
|
||||
|
||||
click_button 'Create Ticket'
|
||||
expect(flash).to eq("Creating Ticket failed: Title can't be blank. Price cents must be greater than 0.")
|
||||
expect(Ticket.count).to eq(0)
|
||||
expect(flash).to eq("Creating Ticket failed: Title can't be blank. Price cents must be greater than or equal to 0.")
|
||||
expect(Ticket.count).to eq(1)
|
||||
end
|
||||
|
||||
context 'Ticket already created' do
|
||||
|
|
@ -44,9 +44,9 @@ feature Ticket do
|
|||
|
||||
scenario 'edit valid ticket', feature: true, js: true do
|
||||
visit admin_conference_tickets_path(conference.short_title)
|
||||
click_link 'Edit'
|
||||
click_link('Edit', href: edit_admin_conference_ticket_path(conference.short_title, ticket.id))
|
||||
|
||||
fill_in 'ticket_title', with: 'Free Ticket'
|
||||
fill_in 'ticket_title', with: 'Event Ticket'
|
||||
fill_in 'ticket_price', with: '50'
|
||||
|
||||
click_button 'Update Ticket'
|
||||
|
|
@ -54,14 +54,14 @@ feature Ticket do
|
|||
ticket.reload
|
||||
# It's necessary to multiply by 100 because the price is in cents
|
||||
expect(ticket.price).to eq(Money.new(50 * 100, 'USD'))
|
||||
expect(ticket.title).to eq('Free Ticket')
|
||||
expect(ticket.title).to eq('Event Ticket')
|
||||
expect(flash).to eq('Ticket successfully updated.')
|
||||
expect(Ticket.count).to eq(1)
|
||||
expect(Ticket.count).to eq(2)
|
||||
end
|
||||
|
||||
scenario 'edit invalid ticket', feature: true, js: true do
|
||||
visit admin_conference_tickets_path(conference.short_title)
|
||||
click_link 'Edit'
|
||||
click_link('Edit', href: edit_admin_conference_ticket_path(conference.short_title, ticket.id))
|
||||
|
||||
fill_in 'ticket_title', with: ''
|
||||
fill_in 'ticket_price', with: '-5'
|
||||
|
|
@ -72,16 +72,16 @@ feature Ticket do
|
|||
# It's necessary to multiply by 100 because the price is in cents
|
||||
expect(ticket.price).to eq(Money.new(100 * 100, 'USD'))
|
||||
expect(ticket.title).to eq('Business Ticket')
|
||||
expect(flash).to eq("Ticket update failed: Title can't be blank. Price cents must be greater than 0.")
|
||||
expect(Ticket.count).to eq(1)
|
||||
expect(flash).to eq("Ticket update failed: Title can't be blank. Price cents must be greater than or equal to 0.")
|
||||
expect(Ticket.count).to eq(2)
|
||||
end
|
||||
|
||||
scenario 'delete ticket', feature: true, js: true do
|
||||
visit admin_conference_tickets_path(conference.short_title)
|
||||
click_link 'Delete'
|
||||
click_link('Delete', href: admin_conference_ticket_path(conference.short_title, ticket.id))
|
||||
|
||||
expect(flash).to eq('Ticket successfully destroyed.')
|
||||
expect(Ticket.count).to eq(0)
|
||||
expect(Ticket.count).to eq(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue