Merge e826bb85eb into 66e17d5ac5
This commit is contained in:
commit
eedb44a228
2 changed files with 21 additions and 0 deletions
|
|
@ -29,6 +29,7 @@ class Registration < ActiveRecord::Base
|
||||||
validate :registration_limit_not_exceed, on: :create
|
validate :registration_limit_not_exceed, on: :create
|
||||||
|
|
||||||
after_create :set_week, :subscribe_to_conference, :send_registration_mail
|
after_create :set_week, :subscribe_to_conference, :send_registration_mail
|
||||||
|
after_destroy :destroy_purchased_tickets
|
||||||
|
|
||||||
def week
|
def week
|
||||||
created_at.strftime('%W').to_i
|
created_at.strftime('%W').to_i
|
||||||
|
|
@ -36,6 +37,13 @@ class Registration < ActiveRecord::Base
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def destroy_purchased_tickets
|
||||||
|
ticket_purchased = TicketPurchase.where(conference_id: conference_id)
|
||||||
|
unless ticket_purchased.empty?
|
||||||
|
ticket_purchased.destroy_all
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def subscribe_to_conference
|
def subscribe_to_conference
|
||||||
Subscription.create(conference_id: conference.id, user_id: user.id)
|
Subscription.create(conference_id: conference.id, user_id: user.id)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -22,4 +22,17 @@ describe 'Registration' do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
describe 'after destroy' do
|
||||||
|
it 'destroys purchased tickets' do
|
||||||
|
conference = build(:conference)
|
||||||
|
registration1 = build(:registration, conference: conference)
|
||||||
|
registration1.save
|
||||||
|
ticket_purchase = build(:ticket_purchase, conference: conference)
|
||||||
|
ticket_purchase.save
|
||||||
|
expect(conference.ticket_purchases.size).to be 1
|
||||||
|
registration1.destroy
|
||||||
|
expect(conference.registrations.size).to be 0
|
||||||
|
expect(conference.ticket_purchases.size).to be 0
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue