From 994745839bc0ffb765768d8c93a18efea11faea7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sat, 10 Apr 2021 20:33:07 +0200 Subject: [PATCH] Simplify tests checking dates are present When we create a record like a debate or an event and we check the page content, we want to make sure that today's date is present, since it's the date where the record is supposed to have been created. This way we avoid querying the database after the browser has been started. --- spec/system/admin/stats_spec.rb | 6 +++--- spec/system/debates_spec.rb | 4 ++-- spec/system/management/proposals_spec.rb | 4 ++-- spec/system/proposals_spec.rb | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/spec/system/admin/stats_spec.rb b/spec/system/admin/stats_spec.rb index 49db027bc..af8701297 100644 --- a/spec/system/admin/stats_spec.rb +++ b/spec/system/admin/stats_spec.rb @@ -216,7 +216,7 @@ describe "Stats", :admin do end context "graphs" do - scenario "event graphs" do + scenario "event graphs", :with_frozen_time do campaign = create(:campaign) visit root_path(track_id: campaign.track_id) @@ -227,9 +227,9 @@ describe "Stats", :admin do end expect(page).to have_content "#{campaign.name} (1)" + within("#graph") do - event_created_at = Ahoy::Event.find_by(name: campaign.name).time - expect(page).to have_content event_created_at.strftime("%Y-%m-%d") + expect(page).to have_content Date.current.strftime("%Y-%m-%d") end end end diff --git a/spec/system/debates_spec.rb b/spec/system/debates_spec.rb index 4064d5a2d..f68cb22bd 100644 --- a/spec/system/debates_spec.rb +++ b/spec/system/debates_spec.rb @@ -201,7 +201,7 @@ describe "Debates" do expect(page).to have_content("-6 votes") end - scenario "Create" do + scenario "Create", :with_frozen_time do author = create(:user) login_as(author) @@ -216,7 +216,7 @@ describe "Debates" do expect(page).to have_content "Debate created successfully." expect(page).to have_content "This is very important because..." expect(page).to have_content author.name - expect(page).to have_content I18n.l(Debate.last.created_at.to_date) + expect(page).to have_content I18n.l(Date.current) end scenario "Create with invisible_captcha honeypot field", :no_js do diff --git a/spec/system/management/proposals_spec.rb b/spec/system/management/proposals_spec.rb index f9dd4f428..1c1b79c7c 100644 --- a/spec/system/management/proposals_spec.rb +++ b/spec/system/management/proposals_spec.rb @@ -4,7 +4,7 @@ describe "Proposals" do let(:user) { create(:user, :level_two) } context "Create" do - scenario "Creating proposals on behalf of someone" do + scenario "Creating proposals on behalf of someone", :with_frozen_time do login_managed_user(user) login_as_manager click_link "Create proposal" @@ -31,7 +31,7 @@ describe "Proposals" do expect(page).to have_content "This is very important because..." expect(page).to have_content "https://www.youtube.com/watch?v=yRYFKcMa_Ek" expect(page).to have_content user.name - expect(page).to have_content I18n.l(Proposal.last.created_at.to_date) + expect(page).to have_content I18n.l(Date.current) expect(page).to have_current_path(management_proposal_path(Proposal.last)) end diff --git a/spec/system/proposals_spec.rb b/spec/system/proposals_spec.rb index 8ca46bdc7..45bfcd627 100644 --- a/spec/system/proposals_spec.rb +++ b/spec/system/proposals_spec.rb @@ -355,7 +355,7 @@ describe "Proposals" do expect(page).to have_css "meta[property='og:title'][content=\'#{proposal.title}\']", visible: :hidden end - scenario "Create and publish" do + scenario "Create and publish", :with_frozen_time do author = create(:user) login_as(author) @@ -387,7 +387,7 @@ describe "Proposals" do expect(page).to have_content author.name expect(page).to have_content "Refugees" expect(page).to have_content "Solidarity" - expect(page).to have_content I18n.l(Proposal.last.created_at.to_date) + expect(page).to have_content I18n.l(Date.current) end scenario "Create with invisible_captcha honeypot field", :no_js do