Skip to content

Commit 8be47fa

Browse files
nolletohennevogel
authored andcommitted
Add timezone tests for cfp.open?
1 parent 6bf34a8 commit 8be47fa

File tree

1 file changed

+120
-15
lines changed

1 file changed

+120
-15
lines changed

spec/models/cfp_spec.rb

Lines changed: 120 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

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

1010
describe 'validations' do
@@ -131,25 +131,130 @@
131131
end
132132

133133
describe '#open?' do
134-
context 'returns false' do
135-
it 'when start and end dates are in the past' do
136-
cfp.start_date = Date.current - 3
137-
cfp.end_date = Date.current - 1
138-
expect(cfp.open?).to be(false)
134+
let!(:server_timezone) { Time.zone }
135+
let(:timezone_pacific) { 'Pacific/Apia' }
136+
137+
after do
138+
Time.use_zone { server_timezone }
139+
end
140+
141+
context 'when is the same timezone between the conference and server' do
142+
before :each do
143+
Time.use_zone { timezone_minus11 }
144+
Timecop.freeze(Time.zone.now)
145+
146+
cfp.program.conference.timezone = timezone_minus11
147+
end
148+
149+
after :each do
150+
Timecop.return
151+
end
152+
153+
context 'when the current day is before call for papers days' do
154+
it 'returns false' do
155+
cfp.start_date = 1.day.from_now
156+
cfp.end_date = 2.days.from_now
157+
158+
expect(cfp).not_to be_open
159+
end
160+
end
161+
162+
context 'when the current day matches call for papers days' do
163+
it 'returns true' do
164+
cfp.start_date = 1.day.ago
165+
cfp.end_date = 1.day.from_now
166+
167+
expect(cfp).to be_open
168+
end
169+
end
170+
171+
context 'when the current day is after call for papers days' do
172+
it 'returns false' do
173+
cfp.start_date = 2.days.ago
174+
cfp.end_date = 1.day.ago
175+
176+
expect(cfp).not_to be_open
177+
end
178+
end
179+
end
180+
181+
context 'when the timezone from conference is behind the server' do
182+
before :each do
183+
Time.use_zone { timezone_pacific }
184+
Timecop.freeze(Time.zone.now)
185+
186+
cfp.program.conference.timezone = timezone_minus11
187+
end
188+
189+
after :each do
190+
Timecop.return
191+
end
192+
193+
context 'when the current day is before call for papers days' do
194+
it 'returns false' do
195+
cfp.start_date = Time.zone.now
196+
cfp.end_date = 1.day.from_now
197+
198+
expect(cfp).not_to be_open
199+
end
200+
end
201+
202+
context 'when the current day matches call for papers days' do
203+
it 'returns true' do
204+
cfp.start_date = 2.days.ago
205+
cfp.end_date = 1.day.ago
206+
207+
expect(cfp).to be_open
208+
end
139209
end
140210

141-
it 'when start and end dates are in the future' do
142-
cfp.start_date = Date.current + 1
143-
cfp.end_date = Date.current + 3
144-
expect(cfp.open?).to be(false)
211+
context 'when the current day is after call for papers days' do
212+
it 'returns false' do
213+
cfp.start_date = 3.days.ago
214+
cfp.end_date = 2.days.ago
215+
216+
expect(cfp).not_to be_open
217+
end
145218
end
146219
end
147220

148-
context 'returns true' do
149-
it 'when start date is in the past and end date is in the future' do
150-
cfp.start_date = Date.current - 1
151-
cfp.end_date = Date.current + 1
152-
expect(cfp.open?).to be(true)
221+
context 'when the timezone from conference is ahead the server' do
222+
before :each do
223+
Time.use_zone { timezone_minus11 }
224+
Timecop.freeze(Time.zone.now)
225+
226+
cfp.program.conference.timezone = timezone_pacific
227+
end
228+
229+
after :each do
230+
Timecop.return
231+
end
232+
233+
context 'when the current day is before call for papers days' do
234+
it 'returns false' do
235+
cfp.start_date = 2.days.from_now
236+
cfp.end_date = 3.days.from_now
237+
238+
expect(cfp).not_to be_open
239+
end
240+
end
241+
242+
context 'when the current day matches call for papers days' do
243+
it 'returns true' do
244+
cfp.start_date = 1.day.from_now
245+
cfp.end_date = 2.days.from_now
246+
247+
expect(cfp).to be_open
248+
end
249+
end
250+
251+
context 'when the current day is after call for papers days' do
252+
it 'returns false' do
253+
cfp.start_date = 1.day.ago
254+
cfp.end_date = Time.zone.now
255+
256+
expect(cfp).not_to be_open
257+
end
153258
end
154259
end
155260
end

0 commit comments

Comments
 (0)