Merge pull request #876 from rishabhs95/delete-tickets-unregistered

Destroying tickets belonging to a user after user unregisters from a conference
This commit is contained in:
Christian Bruckmayer 2016-03-16 12:54:21 -06:00
commit 9e67a1bcd5
2 changed files with 30 additions and 8 deletions

View file

@ -3,6 +3,10 @@
require 'spec_helper'
describe 'Registration' do
let!(:user) { create(:user) }
let!(:conference) { create(:conference) }
let!(:registration1) { create(:registration, conference: conference, user: user) }
describe 'validations' do
it 'has a valid factory' do
expect(build(:registration)).to be_valid
@ -10,16 +14,28 @@ describe 'Registration' do
describe 'registration_limit_not_exceed' do
it 'is not valid when limit exceeded' do
conference = build(:conference)
conference.registration_limit = 1
registration1 = build(:registration, conference: conference)
registration1.save
registration2 = build(:registration, conference: conference)
registration2.save
expect(conference.registrations.size).to be 1
expect(registration2.valid?).to be false
expect(registration2.errors.full_messages).to eq(['Registration limit exceeded'])
expect { create(:registration, conference: conference, user: user) }.to raise_error
expect(user.registrations.size).to be 1
end
end
end
describe '#destroy_purchased_tickets' do
it 'destroys purchased tickets if tickets are purchased' do
create(:ticket_purchase, conference: conference, user: user)
expect(user.registrations.size).to be 1
expect(user.ticket_purchases.size).to be 1
registration1.destroy
expect(user.registrations.size).to be 0
expect(user.ticket_purchases.size).to be 0
end
it 'destroys no tickets if no tickets are purchased' do
expect(user.registrations.size).to be 1
expect(user.ticket_purchases.size).to be 0
registration1.destroy
expect(user.registrations.size).to be 0
expect(user.ticket_purchases.size).to be 0
end
end
end