From b52d381da5e3f9f2c518e8014855da5c0cb0f3f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sat, 10 Apr 2021 13:32:36 +0200 Subject: [PATCH] Simplify emulating last_sign_in_at We were updating the database after starting the browser to emulate the behavior where a user logs in a day before the current request. We can use `current_sign_in_at` instead and devise will automatically copy that value to `last_sign_in_at` after users visit a page. This way we avoid setting up the database after the process runnin the browser has been started. --- spec/system/dashboard/dashboard_spec.rb | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/spec/system/dashboard/dashboard_spec.rb b/spec/system/dashboard/dashboard_spec.rb index 319f0f6c5..a7c132ea3 100644 --- a/spec/system/dashboard/dashboard_spec.rb +++ b/spec/system/dashboard/dashboard_spec.rb @@ -484,10 +484,7 @@ describe "Proposal's dashboard" do end describe "detect_new_actions_after_last_login" do - before do - visit proposal_dashboard_path(proposal) - proposal.author.update!(last_sign_in_at: Date.yesterday) - end + before { proposal.author.update!(current_sign_in_at: 1.day.ago) } scenario "Display tag 'new' on resouce when it is new for author since last login" do resource = create(:dashboard_action, :resource, :active, day_offset: 0, @@ -503,7 +500,7 @@ describe "Proposal's dashboard" do scenario "Not display tag 'new' on resouce when there is not new resources since last login" do resource = create(:dashboard_action, :resource, :active, day_offset: 0, published_proposal: false) - proposal.author.update!(last_sign_in_at: Date.current) + proposal.author.update!(current_sign_in_at: Date.current) visit progress_proposal_dashboard_path(proposal) @@ -526,7 +523,7 @@ describe "Proposal's dashboard" do scenario "Not display tag 'new' on proposed_action when there is not new since last login" do proposed_action = create(:dashboard_action, :proposed_action, :active, day_offset: 0, published_proposal: false) - proposal.author.update!(last_sign_in_at: Date.current) + proposal.author.update!(current_sign_in_at: Date.current) visit progress_proposal_dashboard_path(proposal) @@ -547,7 +544,7 @@ describe "Proposal's dashboard" do scenario "Not display tag 'new' on sidebar when there is not a new resouce since last login" do create(:dashboard_action, :resource, :active, day_offset: 0, published_proposal: false) - proposal.author.update!(last_sign_in_at: Date.current) + proposal.author.update!(current_sign_in_at: Date.current) visit progress_proposal_dashboard_path(proposal)