diff --git a/app/models/conference.rb b/app/models/conference.rb index 8bf16a09..6fa13a4e 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -64,6 +64,8 @@ class Conference < ActiveRecord::Base before_create :add_color before_create :create_email_settings + after_create :create_free_ticket + def date_range_string startstr = 'Unknown - ' endstr = 'Unknown' @@ -647,6 +649,14 @@ class Conference < ActiveRecord::Base create_roles end + ## + # Creates free ticket for the conference + # after the conference has been successfully created + # Will create 1 new record for 'free' ticket + def create_free_ticket + ticket = Ticket.where(conference: self, title: 'Free Access', price_cents: 0).first_or_create!(description: 'Get free access tickets for the conference.') + end + ## # Creates the roles of the conference # after the conference has been successfully created diff --git a/spec/models/conference_spec.rb b/spec/models/conference_spec.rb index 8aebc0cd..f8a5db2b 100755 --- a/spec/models/conference_spec.rb +++ b/spec/models/conference_spec.rb @@ -1583,4 +1583,14 @@ describe Conference do end end end + + describe 'after_create' do + let!(:conference) { create(:conference) } + + it 'creates free tickets' do + free_ticket = Ticket.find_by(conference: conference) + expect(free_ticket).not_to be_nil + expect(free_ticket.price_cents).to eq(0) + end + end end