From 5e9914875c89742e3efd5ba6b59fbab1703368fb Mon Sep 17 00:00:00 2001 From: Petko Bordjukov Date: Sat, 23 May 2015 18:47:08 +0300 Subject: [PATCH] Automatically create an associated CFP with a Conference Make sure there is always an associated unopened call for participation for each conference. --- app/models/conference.rb | 2 ++ spec/models/conference_spec.rb | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/app/models/conference.rb b/app/models/conference.rb index 6c1c44e..d45f920 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -15,6 +15,8 @@ class Conference < ActiveRecord::Base accepts_nested_attributes_for :tracks, :halls, reject_if: :all_blank, allow_destroy: true + after_create :create_call_for_participation + def submissions_grouped_by_day submissions = events.group('date(events.created_at)').select('events.created_at, count(events.id) as number') submissions.group_by { |s| s.created_at.to_date } diff --git a/spec/models/conference_spec.rb b/spec/models/conference_spec.rb index 1cb520a..1a9df0a 100644 --- a/spec/models/conference_spec.rb +++ b/spec/models/conference_spec.rb @@ -99,6 +99,11 @@ RSpec.describe Conference, :type => :model do conference.destroy expect { CallForParticipation.find(call_for_participation.id) }.to raise_exception ActiveRecord::RecordNotFound end + + it 'creates an associated call for participation when the conference is created' do + conference.save + expect(conference.call_for_participation).to be_present + end end it 'accepts nested attributes for tracks' do