From 95eadabe4419a6c50ad836289f97a75d152a8f36 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Mon, 29 Jul 2024 04:31:42 -0400 Subject: [PATCH] Extrude `fill_in_auth_details` method to `ProfileStories` spec support module (#31163) --- spec/support/stories/profile_stories.rb | 10 +++++++--- spec/system/log_in_spec.rb | 12 +++--------- spec/system/oauth_spec.rb | 8 ++------ 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/spec/support/stories/profile_stories.rb b/spec/support/stories/profile_stories.rb index f5fc9a441fd..07eaaca9fb9 100644 --- a/spec/support/stories/profile_stories.rb +++ b/spec/support/stories/profile_stories.rb @@ -3,6 +3,12 @@ module ProfileStories attr_reader :bob, :alice, :alice_bio + def fill_in_auth_details(email, password) + fill_in 'user_email', with: email + fill_in 'user_password', with: password + click_on I18n.t('auth.login') + end + def as_a_registered_user @bob = Fabricate( :user, @@ -16,9 +22,7 @@ module ProfileStories def as_a_logged_in_user as_a_registered_user visit new_user_session_path - fill_in 'user_email', with: email - fill_in 'user_password', with: password - click_on I18n.t('auth.login') + fill_in_auth_details(email, password) end def as_a_logged_in_admin diff --git a/spec/system/log_in_spec.rb b/spec/system/log_in_spec.rb index c64e19d2b7c..8a73c42d2ed 100644 --- a/spec/system/log_in_spec.rb +++ b/spec/system/log_in_spec.rb @@ -17,17 +17,13 @@ describe 'Log in' do end it 'A valid email and password user is able to log in' do - fill_in 'user_email', with: email - fill_in 'user_password', with: password - click_on I18n.t('auth.login') + fill_in_auth_details(email, password) expect(subject).to have_css('div.app-holder') end it 'A invalid email and password user is not able to log in' do - fill_in 'user_email', with: 'invalid_email' - fill_in 'user_password', with: 'invalid_password' - click_on I18n.t('auth.login') + fill_in_auth_details('invalid_email', 'invalid_password') expect(subject).to have_css('.flash-message', text: failure_message('invalid')) end @@ -36,9 +32,7 @@ describe 'Log in' do let(:confirmed_at) { nil } it 'A unconfirmed user is able to log in' do - fill_in 'user_email', with: email - fill_in 'user_password', with: password - click_on I18n.t('auth.login') + fill_in_auth_details(email, password) expect(subject).to have_css('div.admin-wrapper') end diff --git a/spec/system/oauth_spec.rb b/spec/system/oauth_spec.rb index 42ff4a48ac3..5d06f6111ce 100644 --- a/spec/system/oauth_spec.rb +++ b/spec/system/oauth_spec.rb @@ -3,6 +3,8 @@ require 'rails_helper' describe 'Using OAuth from an external app' do + include ProfileStories + subject { visit "/oauth/authorize?#{params.to_query}" } let(:client_app) { Doorkeeper::Application.create!(name: 'test', redirect_uri: about_url(host: Rails.application.config.x.local_domain), scopes: 'read') } @@ -246,12 +248,6 @@ describe 'Using OAuth from an external app' do private - def fill_in_auth_details(email, password) - fill_in 'user_email', with: email - fill_in 'user_password', with: password - click_on I18n.t('auth.login') - end - def fill_in_otp_details(value) fill_in 'user_otp_attempt', with: value click_on I18n.t('auth.login')