[fix]Store current time to a variable to make sure timestamps are the same

This commit is contained in:
Jimmy 2021-04-20 13:48:47 +08:00 committed by CactusPuppy
parent ef119d0fb6
commit 6f9a6e2275
No known key found for this signature in database
GPG key ID: 4B33B0A3E15E2C82
2 changed files with 18 additions and 17 deletions

View file

@ -103,7 +103,7 @@ feature Splashpage do
program.update_attributes!(selected_schedule: selected_schedule) program.update_attributes!(selected_schedule: selected_schedule)
create(:event, program: program, state: 'confirmed') create(:event, program: program, state: 'confirmed')
end end
let!(:current_time) { Time.now.in_time_zone(conference2.timezone) }
before :each do before :each do
sign_in participant sign_in participant
end end
@ -115,8 +115,8 @@ feature Splashpage do
end end
scenario 'shows all events happening next if nothing is happening now' do scenario 'shows all events happening next if nothing is happening now' do
event_schedule1 = create(:event_schedule, event: scheduled_event1, schedule: selected_schedule, start_time: (Time.now.in_time_zone(conference2.timezone) + 1.hour).strftime('%a, %d %b %Y %H:%M:%S')) event_schedule1 = create(:event_schedule, event: scheduled_event1, schedule: selected_schedule, start_time: (current_time + 1.hour).strftime('%a, %d %b %Y %H:%M:%S'))
event_schedule2 = create(:event_schedule, event: scheduled_event2, schedule: selected_schedule, start_time: (Time.now.in_time_zone(conference2.timezone) + 1.hour).strftime('%a, %d %b %Y %H:%M:%S')) event_schedule2 = create(:event_schedule, event: scheduled_event2, schedule: selected_schedule, start_time: (current_time + 1.hour).strftime('%a, %d %b %Y %H:%M:%S'))
visit conference_path(conference2.short_title) visit conference_path(conference2.short_title)
happening_now = page.find('#happening-now') happening_now = page.find('#happening-now')
expect(happening_now).to have_content(event_schedule1.event.title) expect(happening_now).to have_content(event_schedule1.event.title)
@ -124,9 +124,9 @@ feature Splashpage do
end end
scenario 'only shows all events happening now if something is happening now and next' do scenario 'only shows all events happening now if something is happening now and next' do
event_schedule1 = create(:event_schedule, event: scheduled_event1, schedule: selected_schedule, start_time: (Time.now.in_time_zone(conference2.timezone) + 1.hour).strftime('%a, %d %b %Y %H:%M:%S')) event_schedule1 = create(:event_schedule, event: scheduled_event1, schedule: selected_schedule, start_time: (current_time + 1.hour).strftime('%a, %d %b %Y %H:%M:%S'))
event_schedule2 = create(:event_schedule, event: scheduled_event2, schedule: selected_schedule, start_time: (Time.now.in_time_zone(conference2.timezone) + 1.hour).strftime('%a, %d %b %Y %H:%M:%S')) event_schedule2 = create(:event_schedule, event: scheduled_event2, schedule: selected_schedule, start_time: (current_time + 1.hour).strftime('%a, %d %b %Y %H:%M:%S'))
event_schedule3 = create(:event_schedule, event: scheduled_event3, schedule: selected_schedule, start_time: Time.now.in_time_zone(conference2.timezone).strftime('%a, %d %b %Y %H:%M:%S')) event_schedule3 = create(:event_schedule, event: scheduled_event3, schedule: selected_schedule, start_time: current_time.strftime('%a, %d %b %Y %H:%M:%S'))
visit conference_path(conference2.short_title) visit conference_path(conference2.short_title)
happening_now = page.find('#happening-now') happening_now = page.find('#happening-now')
expect(happening_now).to have_content(event_schedule3.event.title) expect(happening_now).to have_content(event_schedule3.event.title)
@ -135,9 +135,9 @@ feature Splashpage do
end end
scenario 'only shows events happening at the earliest time, not at a later time in the future' do scenario 'only shows events happening at the earliest time, not at a later time in the future' do
event_schedule1 = create(:event_schedule, event: scheduled_event1, schedule: selected_schedule, start_time: (Time.now.in_time_zone(conference2.timezone) + 1.hour).strftime('%a, %d %b %Y %H:%M:%S')) event_schedule1 = create(:event_schedule, event: scheduled_event1, schedule: selected_schedule, start_time: (current_time + 1.hour).strftime('%a, %d %b %Y %H:%M:%S'))
event_schedule2 = create(:event_schedule, event: scheduled_event2, schedule: selected_schedule, start_time: (Time.now.in_time_zone(conference2.timezone) + 1.hour).strftime('%a, %d %b %Y %H:%M:%S')) event_schedule2 = create(:event_schedule, event: scheduled_event2, schedule: selected_schedule, start_time: (current_time + 1.hour).strftime('%a, %d %b %Y %H:%M:%S'))
event_schedule3 = create(:event_schedule, event: scheduled_event3, schedule: selected_schedule, start_time: (Time.now.in_time_zone(conference2.timezone) + 2.hours).strftime('%a, %d %b %Y %H:%M:%S')) event_schedule3 = create(:event_schedule, event: scheduled_event3, schedule: selected_schedule, start_time: (current_time + 2.hours).strftime('%a, %d %b %Y %H:%M:%S'))
visit conference_path(conference2.short_title) visit conference_path(conference2.short_title)
happening_now = page.find('#happening-now') happening_now = page.find('#happening-now')
expect(happening_now).to have_content(event_schedule1.event.title) expect(happening_now).to have_content(event_schedule1.event.title)
@ -146,10 +146,10 @@ feature Splashpage do
end end
scenario 'only shows 3 events happening now because of pagination' do scenario 'only shows 3 events happening now because of pagination' do
event_schedule1 = create(:event_schedule, event: scheduled_event1, schedule: selected_schedule, start_time: Time.now.in_time_zone(conference2.timezone).strftime('%a, %d %b %Y %H:%M:%S')) event_schedule1 = create(:event_schedule, event: scheduled_event1, schedule: selected_schedule, start_time: current_time.strftime('%a, %d %b %Y %H:%M:%S'))
event_schedule2 = create(:event_schedule, event: scheduled_event2, schedule: selected_schedule, start_time: Time.now.in_time_zone(conference2.timezone).strftime('%a, %d %b %Y %H:%M:%S')) event_schedule2 = create(:event_schedule, event: scheduled_event2, schedule: selected_schedule, start_time: current_time.strftime('%a, %d %b %Y %H:%M:%S'))
event_schedule3 = create(:event_schedule, event: scheduled_event3, schedule: selected_schedule, start_time: Time.now.in_time_zone(conference2.timezone).strftime('%a, %d %b %Y %H:%M:%S')) event_schedule3 = create(:event_schedule, event: scheduled_event3, schedule: selected_schedule, start_time: current_time.strftime('%a, %d %b %Y %H:%M:%S'))
event_schedule4 = create(:event_schedule, event: scheduled_event4, schedule: selected_schedule, start_time: Time.now.in_time_zone(conference2.timezone).strftime('%a, %d %b %Y %H:%M:%S')) event_schedule4 = create(:event_schedule, event: scheduled_event4, schedule: selected_schedule, start_time: current_time.strftime('%a, %d %b %Y %H:%M:%S'))
visit conference_path(conference2.short_title) visit conference_path(conference2.short_title)
happening_now = page.find('#happening-now') happening_now = page.find('#happening-now')

View file

@ -108,22 +108,23 @@ describe ConferenceHelper, type: :helper do
program.update_attributes!(selected_schedule: selected_schedule) program.update_attributes!(selected_schedule: selected_schedule)
create(:event, program: program, state: 'confirmed', abstract: '`markdown`') create(:event, program: program, state: 'confirmed', abstract: '`markdown`')
end end
let!(:event_schedule1) { create(:event_schedule, event: scheduled_event1, schedule: selected_schedule, start_time: (Time.now.in_time_zone(conference2.timezone) + 1.hour).strftime('%a, %d %b %Y %H:%M:%S')) } let!(:current_time) { Time.now.in_time_zone(conference2.timezone) }
let!(:event_schedule1) { create(:event_schedule, event: scheduled_event1, schedule: selected_schedule, start_time: (current_time + 1.hour).strftime('%a, %d %b %Y %H:%M:%S')) }
let!(:scheduled_event2) do let!(:scheduled_event2) do
program.update_attributes!(selected_schedule: selected_schedule) program.update_attributes!(selected_schedule: selected_schedule)
create(:event, program: program, state: 'confirmed') create(:event, program: program, state: 'confirmed')
end end
let!(:event_schedule2) { create(:event_schedule, event: scheduled_event2, schedule: selected_schedule, start_time: (Time.now.in_time_zone(conference2.timezone) + 1.hour).strftime('%a, %d %b %Y %H:%M:%S')) } let!(:event_schedule2) { create(:event_schedule, event: scheduled_event2, schedule: selected_schedule, start_time: (current_time + 1.hour).strftime('%a, %d %b %Y %H:%M:%S')) }
let!(:scheduled_event3) do let!(:scheduled_event3) do
program.update_attributes!(selected_schedule: selected_schedule) program.update_attributes!(selected_schedule: selected_schedule)
create(:event, program: program, state: 'confirmed') create(:event, program: program, state: 'confirmed')
end end
let!(:event_schedule3) { create(:event_schedule, event: scheduled_event3, schedule: selected_schedule, start_time: (Time.now.in_time_zone(conference2.timezone) - 1.hour).strftime('%a, %d %b %Y %H:%M:%S')) } let!(:event_schedule3) { create(:event_schedule, event: scheduled_event3, schedule: selected_schedule, start_time: (current_time - 1.hour).strftime('%a, %d %b %Y %H:%M:%S')) }
let!(:scheduled_event4) do let!(:scheduled_event4) do
program.update_attributes!(selected_schedule: selected_schedule) program.update_attributes!(selected_schedule: selected_schedule)
create(:event, program: program, state: 'confirmed') create(:event, program: program, state: 'confirmed')
end end
let!(:event_schedule4) { create(:event_schedule, event: scheduled_event4, schedule: selected_schedule, start_time: (Time.now.in_time_zone(conference2.timezone) + 2.hours).strftime('%a, %d %b %Y %H:%M:%S')) } let!(:event_schedule4) { create(:event_schedule, event: scheduled_event4, schedule: selected_schedule, start_time: (current_time + 2.hours).strftime('%a, %d %b %Y %H:%M:%S')) }
it 'returns all the events happening at the earliest time in the future but not later or in the past' do it 'returns all the events happening at the earliest time in the future but not later or in the past' do
events_schedules = get_happening_next_events_schedules(conference2) events_schedules = get_happening_next_events_schedules(conference2)