Add timezone tests for cfp.open?
This commit is contained in:
parent
6bf34a84eb
commit
8be47fa406
1 changed files with 120 additions and 15 deletions
|
|
@ -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
|
end
|
||||||
|
|
||||||
it 'when start and end dates are in the future' do
|
context 'when is the same timezone between the conference and server' do
|
||||||
cfp.start_date = Date.current + 1
|
before :each do
|
||||||
cfp.end_date = Date.current + 3
|
Time.use_zone { timezone_minus11 }
|
||||||
expect(cfp.open?).to be(false)
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'returns true' do
|
context 'when the current day matches call for papers days' do
|
||||||
it 'when start date is in the past and end date is in the future' do
|
it 'returns true' do
|
||||||
cfp.start_date = Date.current - 1
|
cfp.start_date = 1.day.ago
|
||||||
cfp.end_date = Date.current + 1
|
cfp.end_date = 1.day.from_now
|
||||||
expect(cfp.open?).to be(true)
|
|
||||||
|
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
|
||||||
|
|
||||||
|
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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue