Merge pull request #2911 from consul/backport-fix_time_related_specs
Fix time related specs
This commit is contained in:
@@ -46,7 +46,7 @@ module PollsHelper
|
|||||||
end
|
end
|
||||||
|
|
||||||
def voted_before_sign_in(question)
|
def voted_before_sign_in(question)
|
||||||
question.answers.where(author: current_user).any? { |vote| current_user.current_sign_in_at >= vote.updated_at }
|
question.answers.where(author: current_user).any? { |vote| current_user.current_sign_in_at > vote.updated_at }
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -149,11 +149,11 @@ FactoryBot.define do
|
|||||||
end
|
end
|
||||||
|
|
||||||
trait :hidden do
|
trait :hidden do
|
||||||
hidden_at Time.current
|
hidden_at { Time.current }
|
||||||
end
|
end
|
||||||
|
|
||||||
trait :with_ignored_flag do
|
trait :with_ignored_flag do
|
||||||
ignored_flag_at Time.current
|
ignored_flag_at { Time.current }
|
||||||
end
|
end
|
||||||
|
|
||||||
trait :flagged do
|
trait :flagged do
|
||||||
@@ -163,7 +163,7 @@ FactoryBot.define do
|
|||||||
end
|
end
|
||||||
|
|
||||||
trait :with_confirmed_hide do
|
trait :with_confirmed_hide do
|
||||||
confirmed_hide_at Time.current
|
confirmed_hide_at { Time.current }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ FactoryBot.define do
|
|||||||
|
|
||||||
trait :sent do
|
trait :sent do
|
||||||
recipients_count 1
|
recipients_count 1
|
||||||
sent_at Time.current
|
sent_at { Time.current }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -64,15 +64,15 @@ FactoryBot.define do
|
|||||||
end
|
end
|
||||||
|
|
||||||
trait :ignored do
|
trait :ignored do
|
||||||
ignored_at Date.current
|
ignored_at { Date.current }
|
||||||
end
|
end
|
||||||
|
|
||||||
trait :hidden do
|
trait :hidden do
|
||||||
hidden_at Date.current
|
hidden_at { Date.current }
|
||||||
end
|
end
|
||||||
|
|
||||||
trait :with_confirmed_hide do
|
trait :with_confirmed_hide do
|
||||||
confirmed_hide_at Time.current
|
confirmed_hide_at { Time.current }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ feature "Admin Notifications" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context "Index" do
|
context "Index" do
|
||||||
scenario "Valid Admin Notifications" do
|
scenario "Valid Admin Notifications", :with_frozen_time do
|
||||||
draft = create(:admin_notification, segment_recipient: :all_users, title: 'Not yet sent')
|
draft = create(:admin_notification, segment_recipient: :all_users, title: 'Not yet sent')
|
||||||
sent = create(:admin_notification, :sent, segment_recipient: :administrators,
|
sent = create(:admin_notification, :sent, segment_recipient: :administrators,
|
||||||
title: 'Sent one')
|
title: 'Sent one')
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ feature 'Legislation' do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'debate phase' do
|
context 'debate phase' do
|
||||||
scenario 'not open' do
|
scenario 'not open', :with_frozen_time do
|
||||||
process = create(:legislation_process, debate_start_date: Date.current + 1.day, debate_end_date: Date.current + 2.days)
|
process = create(:legislation_process, debate_start_date: Date.current + 1.day, debate_end_date: Date.current + 2.days)
|
||||||
|
|
||||||
visit legislation_process_path(process)
|
visit legislation_process_path(process)
|
||||||
@@ -179,7 +179,7 @@ feature 'Legislation' do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'draft publication phase' do
|
context 'draft publication phase' do
|
||||||
scenario 'not open' do
|
scenario 'not open', :with_frozen_time do
|
||||||
process = create(:legislation_process, draft_publication_date: Date.current + 1.day)
|
process = create(:legislation_process, draft_publication_date: Date.current + 1.day)
|
||||||
|
|
||||||
visit draft_publication_legislation_process_path(process)
|
visit draft_publication_legislation_process_path(process)
|
||||||
@@ -199,7 +199,7 @@ feature 'Legislation' do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'allegations phase' do
|
context 'allegations phase' do
|
||||||
scenario 'not open' do
|
scenario 'not open', :with_frozen_time do
|
||||||
process = create(:legislation_process, allegations_start_date: Date.current + 1.day, allegations_end_date: Date.current + 2.days)
|
process = create(:legislation_process, allegations_start_date: Date.current + 1.day, allegations_end_date: Date.current + 2.days)
|
||||||
|
|
||||||
visit allegations_legislation_process_path(process)
|
visit allegations_legislation_process_path(process)
|
||||||
@@ -219,7 +219,7 @@ feature 'Legislation' do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'final version publication phase' do
|
context 'final version publication phase' do
|
||||||
scenario 'not open' do
|
scenario 'not open', :with_frozen_time do
|
||||||
process = create(:legislation_process, result_publication_date: Date.current + 1.day)
|
process = create(:legislation_process, result_publication_date: Date.current + 1.day)
|
||||||
|
|
||||||
visit result_publication_legislation_process_path(process)
|
visit result_publication_legislation_process_path(process)
|
||||||
|
|||||||
@@ -1,16 +1,8 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
feature 'Residence' do
|
feature 'Residence', :with_frozen_time do
|
||||||
let(:officer) { create(:poll_officer) }
|
let(:officer) { create(:poll_officer) }
|
||||||
|
|
||||||
background do
|
|
||||||
travel_to Time.now # TODO: use `freeze_time` after migrating to Rails 5.
|
|
||||||
end
|
|
||||||
|
|
||||||
after do
|
|
||||||
travel_back
|
|
||||||
end
|
|
||||||
|
|
||||||
feature "Officers without assignments" do
|
feature "Officers without assignments" do
|
||||||
|
|
||||||
scenario "Can not access residence verification" do
|
scenario "Can not access residence verification" do
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
feature 'Officing Results' do
|
feature 'Officing Results', :with_frozen_time do
|
||||||
|
|
||||||
background do
|
background do
|
||||||
travel_to Time.now # TODO: use `freeze_time` after migrating to Rails 5.
|
|
||||||
@poll_officer = create(:poll_officer)
|
@poll_officer = create(:poll_officer)
|
||||||
@officer_assignment = create(:poll_officer_assignment, :final, officer: @poll_officer)
|
@officer_assignment = create(:poll_officer_assignment, :final, officer: @poll_officer)
|
||||||
@poll = @officer_assignment.booth_assignment.poll
|
@poll = @officer_assignment.booth_assignment.poll
|
||||||
@@ -18,10 +17,6 @@ feature 'Officing Results' do
|
|||||||
login_as(@poll_officer.user)
|
login_as(@poll_officer.user)
|
||||||
end
|
end
|
||||||
|
|
||||||
after do
|
|
||||||
travel_back
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario 'Only polls where user is officer for results are accessible' do
|
scenario 'Only polls where user is officer for results are accessible' do
|
||||||
regular_officer_assignment_1 = create(:poll_officer_assignment, officer: @poll_officer)
|
regular_officer_assignment_1 = create(:poll_officer_assignment, officer: @poll_officer)
|
||||||
regular_officer_assignment_2 = create(:poll_officer_assignment, officer: @poll_officer)
|
regular_officer_assignment_2 = create(:poll_officer_assignment, officer: @poll_officer)
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ feature 'Poll Officing' do
|
|||||||
expect(page).not_to have_css('#moderation_menu')
|
expect(page).not_to have_css('#moderation_menu')
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario 'Officing dashboard available for multiple sessions', :js do
|
scenario 'Officing dashboard available for multiple sessions', :js, :with_frozen_time do
|
||||||
poll = create(:poll)
|
poll = create(:poll)
|
||||||
booth = create(:poll_booth)
|
booth = create(:poll_booth)
|
||||||
booth_assignment = create(:poll_booth_assignment, poll: poll, booth: booth)
|
booth_assignment = create(:poll_booth_assignment, poll: poll, booth: booth)
|
||||||
|
|||||||
@@ -387,18 +387,12 @@ feature 'Polls' do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'Booth & Website' do
|
context 'Booth & Website', :with_frozen_time do
|
||||||
|
|
||||||
let(:poll) { create(:poll, summary: "Summary", description: "Description", starts_at: '2017-12-01', ends_at: '2018-02-01') }
|
let(:poll) { create(:poll, summary: "Summary", description: "Description") }
|
||||||
let(:booth) { create(:poll_booth) }
|
let(:booth) { create(:poll_booth) }
|
||||||
let(:officer) { create(:poll_officer) }
|
let(:officer) { create(:poll_officer) }
|
||||||
|
|
||||||
before do
|
|
||||||
allow(Date).to receive(:current).and_return Date.new(2018,1,1)
|
|
||||||
allow(Date).to receive(:today).and_return Date.new(2018,1,1)
|
|
||||||
allow(Time).to receive(:current).and_return Time.zone.parse("2018-01-01 12:00:00")
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario 'Already voted on booth cannot vote on website', :js do
|
scenario 'Already voted on booth cannot vote on website', :js do
|
||||||
|
|
||||||
create(:poll_shift, officer: officer, booth: booth, date: Date.current, task: :vote_collection)
|
create(:poll_shift, officer: officer, booth: booth, date: Date.current, task: :vote_collection)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ require 'rails_helper'
|
|||||||
|
|
||||||
feature "Voter" do
|
feature "Voter" do
|
||||||
|
|
||||||
context "Origin" do
|
context "Origin", :with_frozen_time do
|
||||||
|
|
||||||
let(:poll) { create(:poll, :current) }
|
let(:poll) { create(:poll, :current) }
|
||||||
let(:question) { create(:poll_question, poll: poll) }
|
let(:question) { create(:poll_question, poll: poll) }
|
||||||
@@ -125,12 +125,18 @@ feature "Voter" do
|
|||||||
|
|
||||||
click_link "Sign out"
|
click_link "Sign out"
|
||||||
|
|
||||||
login_as user
|
# Time needs to pass between the moment we vote and the moment
|
||||||
visit poll_path(poll)
|
# we log in; otherwise the link to vote won't be available.
|
||||||
|
# It's safe to advance one second because this test isn't
|
||||||
|
# affected by possible date changes.
|
||||||
|
travel 1.second do
|
||||||
|
login_as user
|
||||||
|
visit poll_path(poll)
|
||||||
|
|
||||||
within("#poll_question_#{question.id}_answers") do
|
within("#poll_question_#{question.id}_answers") do
|
||||||
expect(page).to have_link(answer_yes.title)
|
expect(page).to have_link(answer_yes.title)
|
||||||
expect(page).to have_link(answer_no.title)
|
expect(page).to have_link(answer_no.title)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -82,6 +82,14 @@ RSpec.configure do |config|
|
|||||||
Bullet.end_request
|
Bullet.end_request
|
||||||
end
|
end
|
||||||
|
|
||||||
|
config.before(:each, :with_frozen_time) do
|
||||||
|
travel_to Time.now # TODO: use `freeze_time` after migrating to Rails 5.
|
||||||
|
end
|
||||||
|
|
||||||
|
config.after(:each, :with_frozen_time) do
|
||||||
|
travel_back
|
||||||
|
end
|
||||||
|
|
||||||
# Allows RSpec to persist some state between runs in order to support
|
# Allows RSpec to persist some state between runs in order to support
|
||||||
# the `--only-failures` and `--next-failure` CLI options.
|
# the `--only-failures` and `--next-failure` CLI options.
|
||||||
config.example_status_persistence_file_path = "spec/examples.txt"
|
config.example_status_persistence_file_path = "spec/examples.txt"
|
||||||
|
|||||||
Reference in New Issue
Block a user