diff --git a/app/models/call_for_participation.rb b/app/models/call_for_participation.rb new file mode 100644 index 0000000..25d23e9 --- /dev/null +++ b/app/models/call_for_participation.rb @@ -0,0 +1,3 @@ +class CallForParticipation < ActiveRecord::Base + belongs_to :conference +end diff --git a/app/models/conference.rb b/app/models/conference.rb index 16bc384..4162112 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -11,7 +11,7 @@ class Conference < ActiveRecord::Base has_many :tracks has_many :halls has_many :events, through: :tracks - + has_one :call_for_participation, dependent: :destroy accepts_nested_attributes_for :tracks, :halls, reject_if: :all_blank, allow_destroy: true diff --git a/db/migrate/20150420154042_create_call_for_participations.rb b/db/migrate/20150420154042_create_call_for_participations.rb new file mode 100644 index 0000000..0f3bf5e --- /dev/null +++ b/db/migrate/20150420154042_create_call_for_participations.rb @@ -0,0 +1,11 @@ +class CreateCallForParticipations < ActiveRecord::Migration + def change + create_table :call_for_participations do |t| + t.references :conference, index: true, foreign_key: true + t.datetime :opens_at + t.datetime :closes_at + + t.timestamps null: false + end + end +end diff --git a/spec/factories/call_for_participations.rb b/spec/factories/call_for_participations.rb new file mode 100644 index 0000000..ceba82e --- /dev/null +++ b/spec/factories/call_for_participations.rb @@ -0,0 +1,8 @@ +FactoryGirl.define do + factory :call_for_participation do + conference nil +opens_at "2015-04-20 18:40:43" +closes_at "2015-04-20 18:40:43" + end + +end diff --git a/spec/models/call_for_participation_spec.rb b/spec/models/call_for_participation_spec.rb new file mode 100644 index 0000000..1702599 --- /dev/null +++ b/spec/models/call_for_participation_spec.rb @@ -0,0 +1,9 @@ +require 'rails_helper' + +RSpec.describe CallForParticipation, type: :model do + it 'belongs to a conference' do + conference = create :conference + cfp = create(:call_for_participation, conference_id: conference.id) + expect(CallForParticipation.find(cfp.id).conference).to eq conference + end +end diff --git a/spec/models/conference_spec.rb b/spec/models/conference_spec.rb index d615b52..1cb520a 100644 --- a/spec/models/conference_spec.rb +++ b/spec/models/conference_spec.rb @@ -81,6 +81,26 @@ RSpec.describe Conference, :type => :model do end end + describe 'call for participation association' do + let(:conference) { build :conference } + let(:call_for_participation) { build :call_for_participation } + + before(:each) do + conference.save + call_for_participation.conference = conference + call_for_participation.save + end + + it 'has one call for participation' do + expect(conference.call_for_participation).to eq call_for_participation + end + + it 'destroys the associated call for participation when destroyed' do + conference.destroy + expect { CallForParticipation.find(call_for_participation.id) }.to raise_exception ActiveRecord::RecordNotFound + end + end + it 'accepts nested attributes for tracks' do track_attributes = build(:track, conference: nil).attributes conference = create :conference