validate cfp start_date before end_date and end_date before conference.end_date

This commit is contained in:
Stella 2014-11-29 20:00:26 +02:00
parent 1edb4bff9e
commit 6e026746a9
7 changed files with 62 additions and 7 deletions

38
spec/models/cfp_spec.rb Normal file
View file

@ -0,0 +1,38 @@
require 'spec_helper'
describe CallForPaper do
let!(:conference) { create(:conference, end_date: Date.today) }
describe '#before_end_of_conference' do
describe 'fails to save cfp' do
it 'when cfp end_date is after conference end_date' do
cfp = build(:call_for_paper, end_date: Date.today + 1, conference_id: conference.id)
expect(cfp.valid?).to be false
end
it 'when cfp start_date is after conference end_date' do
cfp = build(:call_for_paper, end_date: Date.today + 1, conference_id: conference.id)
expect(cfp.valid?).to be false
end
end
describe 'successfully saves cfp' do
it 'when cfp end_date and start_date are not after conference end_date' do
cfp = build(:call_for_paper, start_date: Date.today - 2, end_date: Date.today - 1, conference_id: conference.id)
expect(cfp.valid?).to be true
end
end
end
describe '#start_after_end_date' do
it 'fails when cfp start_date is after cfp end_date' do
cfp = build(:call_for_paper, start_date: Date.today - 1, end_date: Date.today - 2, conference_id: conference.id)
expect(cfp.valid?).to be false
end
it 'succeeds when cfp start_date is after cfp end_date' do
cfp = build(:call_for_paper, start_date: Date.today - 2, end_date: Date.today - 1, conference_id: conference.id)
expect(cfp.valid?).to be true
end
end
end

View file

@ -4,7 +4,7 @@ require 'spec_helper'
describe Conference do
let(:subject) { create(:conference) }
let(:subject) { create(:conference, end_date: '2014-06-30') }
describe '#write_event_distribution_to_db' do