Added tests for program#any_event_for_this_date?

This commit is contained in:
Naman Gupta 2017-11-17 00:02:23 +05:30 committed by Stella Rouzi
parent 6a1d757f43
commit 6eb8c8d6ae
3 changed files with 51 additions and 3 deletions

View file

@ -2,7 +2,7 @@ require 'spec_helper'
describe Program do
subject { create(:program) }
let!(:conference) { create(:conference, end_date: Date.today + 3) }
let!(:conference) { create(:conference, end_date: Date.current + 3) }
let!(:program) { conference.program }
describe 'association' do
@ -241,6 +241,54 @@ describe Program do
end
end
describe '#any_event_for_this_date?' do
let(:event){ create(:event, program: program) }
context 'when no schedule is selected for the conference' do
let(:schedule) { create(:schedule, program: program) }
let!(:event_schedule) { create(:event_schedule, event: event, schedule: schedule, start_time: DateTime.parse("#{Date.current + 1} 10:00").utc) }
it 'returns false irrespective of any date' do
expect(program.any_event_for_this_date?(Date.current + 1)).to eq false
end
it 'returns false if date passed is empty' do
expect(program.any_event_for_this_date?('')).to eq false
end
it 'returns false if date passed is nil' do
expect(program.any_event_for_this_date?(nil)).to eq false
end
end
context 'when schedule is selected for the conference' do
let(:schedule) { create(:schedule, program: program) }
let!(:event_schedule) { create(:event_schedule, event: event, schedule: schedule, start_time: DateTime.parse("#{Date.current + 1} 10:00").utc) }
before :each do
program.selected_schedule = event_schedule.schedule
program.save!
end
it 'returns true if there is any event for this date' do
expect(program.any_event_for_this_date?(Date.current + 1)).to eq true
end
it 'returns false if there is no event for this date' do
expect(program.any_event_for_this_date?(Date.current + 2)).to eq false
end
it 'returns false if date passed is empty' do
expect(program.any_event_for_this_date?('')).to eq false
end
it 'returns false if date passed is nil' do
expect(program.any_event_for_this_date?(nil)).to eq false
end
end
end
describe '#cfp' do
it 'returns the cfp for events' do
create(:cfp, cfp_type: 'events', program: program, end_date: Date.current + 1)