|
4 | 4 |
|
5 | 5 | describe Cfp do |
6 | 6 | 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) } |
8 | 8 | let!(:cfp) { create(:cfp, cfp_type: 'events', start_date: Date.today - 2, end_date: Date.today - 1, program_id: conference.program.id) } |
9 | 9 |
|
10 | 10 | describe 'validations' do |
|
131 | 131 | end |
132 | 132 |
|
133 | 133 | 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 |
139 | 209 | end |
140 | 210 |
|
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 |
145 | 218 | end |
146 | 219 | end |
147 | 220 |
|
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 |
153 | 258 | end |
154 | 259 | end |
155 | 260 | end |
|
0 commit comments