This commit is contained in:
Felipe Nolleto Nascimento 2026-08-11 21:01:23 -03:00 committed by GitHub
commit 82952dc918
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 123 additions and 16 deletions

View file

@ -75,7 +75,9 @@ class Cfp < ApplicationRecord
# * +false+ -> If the CFP is not set or today isn't in the CFP period. # * +false+ -> If the CFP is not set or today isn't in the CFP period.
# * +true+ -> If today is in the CFP period. # * +true+ -> If today is in the CFP period.
def open? 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 end
## ##

View file

@ -4,7 +4,7 @@ require 'spec_helper'
describe Cfp do describe Cfp do
subject { create(:cfp) } 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) } 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 describe 'validations' do
@ -131,25 +131,130 @@ describe Cfp do
end end
describe '#open?' do describe '#open?' do
context 'returns false' do let!(:server_timezone) { Time.zone }
it 'when start and end dates are in the past' do let(:timezone_pacific) { 'Pacific/Apia' }
cfp.start_date = Date.current - 3
cfp.end_date = Date.current - 1 after do
expect(cfp.open?).to be(false) 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 end
it 'when start and end dates are in the future' do after :each do
cfp.start_date = Date.current + 1 Timecop.return
cfp.end_date = Date.current + 3 end
expect(cfp.open?).to be(false)
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
end end
context 'returns true' do context 'when the timezone from conference is behind the server' do
it 'when start date is in the past and end date is in the future' do before :each do
cfp.start_date = Date.current - 1 Time.use_zone { timezone_pacific }
cfp.end_date = Date.current + 1 Timecop.freeze(Time.zone.now)
expect(cfp.open?).to be(true)
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
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 '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 end
end end