Merge pull request #1635 from siddhantbajaj/user-registration-ticket

One user one registration ticket
This commit is contained in:
Ana María Martínez Gómez 2017-09-07 10:30:50 +02:00 committed by GitHub
commit 135241a56c
8 changed files with 104 additions and 21 deletions

View file

@ -3,7 +3,9 @@ require 'spec_helper'
feature Registration do
let!(:ticket) { create(:ticket) }
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!(:first_registration_ticket) { create(:registration_ticket, price_cents: 0) }
let!(:second_registration_ticket) { create(:registration_ticket, price_cents: 0) }
let!(:conference) { create(:conference, title: 'ExampleCon', tickets: [ticket, free_ticket, first_registration_ticket, second_registration_ticket], registration_period: create(:registration_period, start_date: 3.days.ago)) }
let!(:participant) { create(:user) }
context 'as a participant' do
@ -106,6 +108,38 @@ feature Registration do
expect(purchase.quantity).to eq(5)
expect(purchase.paid).to be true
end
scenario 'purchases more than one registration tickets of a single type' 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__#{first_registration_ticket.id}", with: '5'
expect(current_path).to eq(conference_tickets_path(conference.short_title))
click_button 'Continue'
expect(current_path).to eq(conference_tickets_path(conference.short_title))
end
scenario 'purchases one registration ticket of a different types' 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__#{first_registration_ticket.id}", with: '1'
fill_in "tickets__#{second_registration_ticket.id}", with: '1'
expect(current_path).to eq(conference_tickets_path(conference.short_title))
click_button 'Continue'
expect(flash).to eq('Oops, something went wrong with your purchase! You cannot buy more than one registration tickets.')
expect(current_path).to eq(conference_tickets_path(conference.short_title))
end
end
context 'who is registered' do

View file

@ -34,6 +34,22 @@ describe TicketPurchase do
it 'is valid with a quantity greater than zero' do
should allow_value(1).for(:quantity)
end
describe 'one_registration_ticket_per_user' do
let(:registration_ticket) { create(:registration_ticket) }
let(:ticket_purchase) { build(:ticket_purchase, ticket: registration_ticket, quantity: 1) }
it 'it is valid, if quantity for registration tickets is less than or equal to one' do
expect(ticket_purchase.valid?).to eq true
end
it 'it is not valid, if quantity for registration tickets is greater than to one' do
ticket_purchase.quantity = 4
expect(ticket_purchase.valid?).to eq false
expect(ticket_purchase.errors[:quantity]).to eq ['cannot be greater than one for registration tickets.']
end
end
end
describe 'self#purchase' do