diff --git a/app/models/call_for_participation.rb b/app/models/call_for_participation.rb index 6862cfc..2011576 100644 --- a/app/models/call_for_participation.rb +++ b/app/models/call_for_participation.rb @@ -1,5 +1,17 @@ class CallForParticipation < ActiveRecord::Base belongs_to :conference + + def open! + self.opens_at = Time.now unless self.opens_at.present? + self.closes_at = nil + save + end + + def close! + self.closes_at = Time.now + save + end + def open? self.opens_at.present? and self.opens_at < Time.now end diff --git a/spec/factories/call_for_participations.rb b/spec/factories/call_for_participations.rb index ceba82e..479ac0f 100644 --- a/spec/factories/call_for_participations.rb +++ b/spec/factories/call_for_participations.rb @@ -1,8 +1,4 @@ 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 index 184169f..24a6ce6 100644 --- a/spec/models/call_for_participation_spec.rb +++ b/spec/models/call_for_participation_spec.rb @@ -70,4 +70,34 @@ RSpec.describe CallForParticipation, type: :model do expect(cfp.in_progress?).to be false end end + + describe '#open!' do + it 'changes the status of the CFP to open' do + expect { cfp.open! }.to change { cfp.open? }.from(false).to(true) + end + + it 'does not change the open time of the CFP when it has already been set' do + cfp.opens_at = 10.minutes.ago + expect { cfp.open! }.to_not change { cfp.opens_at } + end + + it 'unsets the close time of the CFP' do + cfp.closes_at = 10.minutes.ago + expect { cfp.open! }.to change { cfp.closes_at }.to(nil) + end + + it 'saves the record' do + expect { cfp.open! }.to change { cfp.persisted? }.from(false).to(true) + end + end + + describe '#close!' do + it 'changes the status of the CFP to closed' do + expect { cfp.close! }.to change { cfp.closed? }.from(false).to(true) + end + + it 'saves the record' do + expect { cfp.close! }.to change { cfp.persisted? }.from(false).to(true) + end + end end