From 8e1c6f6db55df54ccad2242986ce0e39992bae71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 13 Mar 2025 01:48:29 +0100 Subject: [PATCH] Re-use methods to login through the form in tests We were calling these methods in some places, so, for consistency, we're now calling them when possible. --- spec/system/account_spec.rb | 6 +---- spec/system/moderation/users_spec.rb | 6 +---- spec/system/multitenancy_spec.rb | 15 +++--------- spec/system/users_auth_spec.rb | 34 +++++----------------------- 4 files changed, 11 insertions(+), 50 deletions(-) diff --git a/spec/system/account_spec.rb b/spec/system/account_spec.rb index 772373dfd..9bea31abe 100644 --- a/spec/system/account_spec.rb +++ b/spec/system/account_spec.rb @@ -72,11 +72,7 @@ describe "Account" do visit_in_email("Confirm my account") logout - visit root_path - click_link "Sign in" - fill_in "user_login", with: "new_user_email@example.com" - fill_in "user_password", with: "new_password" - click_button "Enter" + login_through_form_with("new_user_email@example.com", password: "new_password") expect(page).to have_content "You have been signed in successfully." diff --git a/spec/system/moderation/users_spec.rb b/spec/system/moderation/users_spec.rb index 8de8df186..b9bd1ffa3 100644 --- a/spec/system/moderation/users_spec.rb +++ b/spec/system/moderation/users_spec.rb @@ -43,11 +43,7 @@ describe "Moderate users" do expect(page).to have_content "You have been signed out successfully" - within("#notice") { click_button "Close" } - click_link "Sign in" - fill_in "user_login", with: citizen.email - fill_in "user_password", with: citizen.password - click_button "Enter" + login_through_form_as(citizen) expect(page).to have_content "Invalid Email or username or password" expect(page).to have_current_path(new_user_session_path) diff --git a/spec/system/multitenancy_spec.rb b/spec/system/multitenancy_spec.rb index 85bad8941..57777ac15 100644 --- a/spec/system/multitenancy_spec.rb +++ b/spec/system/multitenancy_spec.rb @@ -143,19 +143,13 @@ describe "Multitenancy", :seed_tenants do Tenant.switch("mars") { create(:user, email: "marty@consul.dev", password: "20151021") } with_subdomain("mars") do - visit new_user_session_path - fill_in "Email or username", with: "marty@consul.dev" - fill_in "Password", with: "20151021" - click_button "Enter" + login_through_form_with("marty@consul.dev", password: "20151021") expect(page).to have_content "You have been signed in successfully." end with_subdomain("venus") do - visit new_user_session_path - fill_in "Email or username", with: "marty@consul.dev" - fill_in "Password", with: "20151021" - click_button "Enter" + login_through_form_with("marty@consul.dev", password: "20151021") expect(page).to have_content "Invalid Email or username or password." end @@ -163,10 +157,7 @@ describe "Multitenancy", :seed_tenants do scenario "Uses the right tenant after failing to sign in" do with_subdomain("mars") do - visit new_user_session_path - fill_in "Email or username", with: "wrong@consul.dev" - fill_in "Password", with: "wrong" - click_button "Enter" + login_through_form_with("wrong@consul.dev", password: "wrong") expect(page).to have_content "Invalid Email or username or password" expect(page).to have_css "html.tenant-mars" diff --git a/spec/system/users_auth_spec.rb b/spec/system/users_auth_spec.rb index cf0b1b55d..70ae3ea79 100644 --- a/spec/system/users_auth_spec.rb +++ b/spec/system/users_auth_spec.rb @@ -62,11 +62,7 @@ describe "Users" do scenario "sign in with email" do create(:user, email: "manuela@consul.dev", password: "judgementday") - visit "/" - click_link "Sign in" - fill_in "Email or username", with: "manuela@consul.dev" - fill_in "Password", with: "judgementday" - click_button "Enter" + login_through_form_with("manuela@consul.dev", password: "judgementday") expect(page).to have_content "You have been signed in successfully." end @@ -74,11 +70,7 @@ describe "Users" do scenario "Sign in with username" do create(:user, username: "中村広", email: "ash@nostromo.dev", password: "xenomorph") - visit "/" - click_link "Sign in" - fill_in "Email or username", with: "中村広" - fill_in "Password", with: "xenomorph" - click_button "Enter" + login_through_form_with("中村広", password: "xenomorph") expect(page).to have_content "You have been signed in successfully." end @@ -87,11 +79,7 @@ describe "Users" do u1 = create(:user, username: "Spidey", email: "peter@nyc.dev", password: "greatpower") u2 = create(:user, username: "peter@nyc.dev", email: "venom@nyc.dev", password: "symbiote") - visit "/" - click_link "Sign in" - fill_in "Email or username", with: "peter@nyc.dev" - fill_in "Password", with: "greatpower" - click_button "Enter" + login_through_form_with("peter@nyc.dev", password: "greatpower") expect(page).to have_content "You have been signed in successfully." expect(page).to have_link "My content", href: user_path(u1) @@ -101,11 +89,7 @@ describe "Users" do expect(page).to have_content "You have been signed out successfully." - within("#notice") { click_button "Close" } - click_link "Sign in" - fill_in "Email or username", with: "peter@nyc.dev" - fill_in "Password", with: "symbiote" - click_button "Enter" + login_through_form_with("peter@nyc.dev", password: "symbiote") expect(page).not_to have_content "You have been signed in successfully." expect(page).to have_content "Invalid Email or username or password." @@ -606,10 +590,7 @@ describe "Users" do user = create(:administrator).user user.update!(password_changed_at: 1.year.ago) - visit new_user_session_path - fill_in "Email or username", with: user.email - fill_in "Password", with: user.password - click_button "Enter" + login_through_form_as(user) expect(page).to have_content "Your password is expired" @@ -645,10 +626,7 @@ describe "Users" do user = create(:administrator).user user.update!(password_changed_at: 1.year.ago, password: "123456789") - visit new_user_session_path - fill_in "Email or username", with: user.email - fill_in "Password", with: user.password - click_button "Enter" + login_through_form_as(user) expect(page).to have_content "Your password is expired"