From 61f3d346535f05cbd037fff87b0fe1fa5496b098 Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Fri, 16 Aug 2024 19:34:03 -0400 Subject: [PATCH] Pull out login helper --- test/application_system_test_case.rb | 11 +++++++++++ test/system/sessions_test.rb | 15 ++------------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb index e2db3a5..e3e8707 100644 --- a/test/application_system_test_case.rb +++ b/test/application_system_test_case.rb @@ -4,4 +4,15 @@ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase driven_by :selenium, using: ENV["VISIBLE_SYSTEM_TESTS"].present? ? :chrome : :headless_chrome, screen_size: [ 1400, 1400 ] + + def login(email, password = "secret") + visit new_session_url + + fill_in "Email", with: email + fill_in "Password", with: "secret" + + click_on "Create Session" + + assert_text "Session was successfully created" + end end diff --git a/test/system/sessions_test.rb b/test/system/sessions_test.rb index d0ea7fc..958d1a5 100644 --- a/test/system/sessions_test.rb +++ b/test/system/sessions_test.rb @@ -6,24 +6,13 @@ class SessionsTest < ApplicationSystemTestCase end test "should create session" do - visit new_session_url - - fill_in "Email", with: @user.email - fill_in "Password", with: "secret" - - click_on "Create Session" + login(@user.email) assert_text "Session was successfully created" end test "should destroy Session" do - visit new_session_url - - fill_in "Email", with: @user.email - fill_in "Password", with: "secret" - - click_on "Create Session" - assert_text "Session was successfully created" + login(@user.email) visit root_url click_on "Log out", match: :first