Introduce CallForParticipation status predicates
Introduce the #open? #closed? and #in_progress? methods for the CallForParticipation model.
This commit is contained in:
parent
749f8ec30d
commit
5e15a055e1
|
@ -1,3 +1,14 @@
|
||||||
class CallForParticipation < ActiveRecord::Base
|
class CallForParticipation < ActiveRecord::Base
|
||||||
belongs_to :conference
|
belongs_to :conference
|
||||||
|
def open?
|
||||||
|
self.opens_at.present? and self.opens_at < Time.now
|
||||||
|
end
|
||||||
|
|
||||||
|
def closed?
|
||||||
|
self.closes_at.present? and self.closes_at < Time.now
|
||||||
|
end
|
||||||
|
|
||||||
|
def in_progress?
|
||||||
|
open? and not closed?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,9 +1,73 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe CallForParticipation, type: :model do
|
RSpec.describe CallForParticipation, type: :model do
|
||||||
|
let(:cfp) { build :call_for_participation }
|
||||||
|
|
||||||
it 'belongs to a conference' do
|
it 'belongs to a conference' do
|
||||||
conference = create :conference
|
conference = create :conference
|
||||||
cfp = create(:call_for_participation, conference_id: conference.id)
|
cfp = create(:call_for_participation, conference_id: conference.id)
|
||||||
expect(CallForParticipation.find(cfp.id).conference).to eq conference
|
expect(CallForParticipation.find(cfp.id).conference).to eq conference
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#open?' do
|
||||||
|
it 'returns true when the CFP has an opens_at date in the past' do
|
||||||
|
cfp.opens_at = 10.minutes.ago
|
||||||
|
|
||||||
|
expect(cfp.open?).to be true
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns false when the CFP has no opens_at date' do
|
||||||
|
cfp.opens_at = nil
|
||||||
|
|
||||||
|
expect(cfp.open?).to be false
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns false when the CFP has an opens_at date in the future' do
|
||||||
|
cfp.opens_at = 10.minutes.from_now
|
||||||
|
|
||||||
|
expect(cfp.open?).to be false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#closed?' do
|
||||||
|
it 'returns true when the CFP has a closes_at date in the past' do
|
||||||
|
cfp.closes_at = 10.minutes.ago
|
||||||
|
|
||||||
|
expect(cfp.closed?).to be true
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns false when the CFP has no closes_at date' do
|
||||||
|
cfp.closes_at = nil
|
||||||
|
|
||||||
|
expect(cfp.closed?).to be false
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns false when the CFP has a closes_at date in the future' do
|
||||||
|
cfp.closes_at = 10.minutes.from_now
|
||||||
|
|
||||||
|
expect(cfp.closed?).to be false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#in_progress?' do
|
||||||
|
it 'returns true when the CFP has been opened and has not been closed' do
|
||||||
|
expect(cfp).to receive(:open?) { true }
|
||||||
|
expect(cfp).to receive(:closed?) { false }
|
||||||
|
|
||||||
|
expect(cfp.in_progress?).to be true
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns false when the CFP has not been opened' do
|
||||||
|
expect(cfp).to receive(:open?) { false }
|
||||||
|
|
||||||
|
expect(cfp.in_progress?).to be false
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns false when the CFP has been closed' do
|
||||||
|
expect(cfp).to receive(:open?) { true }
|
||||||
|
expect(cfp).to receive(:closed?) { true }
|
||||||
|
|
||||||
|
expect(cfp.in_progress?).to be false
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue