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.
This commit is contained in:
Javi Martín
2025-03-13 01:48:29 +01:00
parent 8774488650
commit 8e1c6f6db5
4 changed files with 11 additions and 50 deletions

View File

@@ -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."

View File

@@ -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)

View File

@@ -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"

View File

@@ -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"