Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/models/cfp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ def remaining_days(date = Date.today)
# * +false+ -> If the CFP is not set or today isn't in the CFP period.
# * +true+ -> If today is in the CFP period.
def open?
(start_date..end_date).cover?(Date.current)
current_date = Time.now.in_time_zone(program.conference.timezone).to_date

(start_date..end_date).cover?(current_date)
end

##
Expand Down
135 changes: 120 additions & 15 deletions spec/models/cfp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

describe Cfp do
subject { create(:cfp) }
let!(:conference) { create(:conference, end_date: Date.today) }
let!(:conference) { create(:conference, start_date: Date.today - 1, end_date: Date.today) }
let!(:cfp) { create(:cfp, cfp_type: 'events', start_date: Date.today - 2, end_date: Date.today - 1, program_id: conference.program.id) }

describe 'validations' do
Expand Down Expand Up @@ -131,25 +131,130 @@
end

describe '#open?' do
context 'returns false' do
it 'when start and end dates are in the past' do
cfp.start_date = Date.current - 3
cfp.end_date = Date.current - 1
expect(cfp.open?).to be(false)
let!(:server_timezone) { Time.zone }
let(:timezone_pacific) { 'Pacific/Apia' }

after do
Time.use_zone { server_timezone }
end

context 'when is the same timezone between the conference and server' do
before :each do
Time.use_zone { timezone_minus11 }
Timecop.freeze(Time.zone.now)

cfp.program.conference.timezone = timezone_minus11
end

after :each do
Timecop.return
end

context 'when the current day is before call for papers days' do
it 'returns false' do
cfp.start_date = 1.day.from_now
cfp.end_date = 2.days.from_now

expect(cfp).not_to be_open
end
end

context 'when the current day matches call for papers days' do
it 'returns true' do
cfp.start_date = 1.day.ago
cfp.end_date = 1.day.from_now

expect(cfp).to be_open
end
end

context 'when the current day is after call for papers days' do
it 'returns false' do
cfp.start_date = 2.days.ago
cfp.end_date = 1.day.ago

expect(cfp).not_to be_open
end
end
end

context 'when the timezone from conference is behind the server' do
before :each do
Time.use_zone { timezone_pacific }
Timecop.freeze(Time.zone.now)

cfp.program.conference.timezone = timezone_minus11
end

after :each do
Timecop.return
end

context 'when the current day is before call for papers days' do
it 'returns false' do
cfp.start_date = Time.zone.now
cfp.end_date = 1.day.from_now

expect(cfp).not_to be_open
end
end

context 'when the current day matches call for papers days' do
it 'returns true' do
cfp.start_date = 2.days.ago
cfp.end_date = 1.day.ago

expect(cfp).to be_open
end
end

it 'when start and end dates are in the future' do
cfp.start_date = Date.current + 1
cfp.end_date = Date.current + 3
expect(cfp.open?).to be(false)
context 'when the current day is after call for papers days' do
it 'returns false' do
cfp.start_date = 3.days.ago
cfp.end_date = 2.days.ago

expect(cfp).not_to be_open
end
end
end

context 'returns true' do
it 'when start date is in the past and end date is in the future' do
cfp.start_date = Date.current - 1
cfp.end_date = Date.current + 1
expect(cfp.open?).to be(true)
context 'when the timezone from conference is ahead the server' do
before :each do
Time.use_zone { timezone_minus11 }
Timecop.freeze(Time.zone.now)

cfp.program.conference.timezone = timezone_pacific
end

after :each do
Timecop.return
end

context 'when the current day is before call for papers days' do
it 'returns false' do
cfp.start_date = 2.days.from_now
cfp.end_date = 3.days.from_now

expect(cfp).not_to be_open
end
end

context 'when the current day matches call for papers days' do
it 'returns true' do
cfp.start_date = 1.day.from_now
cfp.end_date = 2.days.from_now

expect(cfp).to be_open
end
end

context 'when the current day is after call for papers days' do
it 'returns false' do
cfp.start_date = 1.day.ago
cfp.end_date = Time.zone.now

expect(cfp).not_to be_open
end
end
end
end
Expand Down
Loading