From a596f3479b01e7be88f9730c5ec6f7a6206acb87 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Mon, 16 Dec 2024 03:12:36 -0500 Subject: [PATCH] Convert `settings/login_activities` controller spec to system spec (#33306) --- .../login_activities_controller_spec.rb | 29 ---------------- spec/system/settings/login_activities_spec.rb | 34 +++++++++++++++++++ 2 files changed, 34 insertions(+), 29 deletions(-) delete mode 100644 spec/controllers/settings/login_activities_controller_spec.rb create mode 100644 spec/system/settings/login_activities_spec.rb diff --git a/spec/controllers/settings/login_activities_controller_spec.rb b/spec/controllers/settings/login_activities_controller_spec.rb deleted file mode 100644 index 3447620abb..0000000000 --- a/spec/controllers/settings/login_activities_controller_spec.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -RSpec.describe Settings::LoginActivitiesController do - render_views - - let!(:user) { Fabricate(:user) } - let!(:login_activity) { Fabricate :login_activity, user: user } - - before do - sign_in user, scope: :user - end - - describe 'GET #index' do - before do - get :index - end - - it 'returns http success with private cache control headers', :aggregate_failures do - expect(response).to have_http_status(200) - expect(response.headers['Cache-Control']).to include('private, no-store') - expect(response.body) - .to include(login_activity.user_agent) - .and include(login_activity.authentication_method) - .and include(login_activity.ip.to_s) - end - end -end diff --git a/spec/system/settings/login_activities_spec.rb b/spec/system/settings/login_activities_spec.rb new file mode 100644 index 0000000000..ff89c3f37e --- /dev/null +++ b/spec/system/settings/login_activities_spec.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe 'Login activities page' do + let!(:user) { Fabricate :user } + let!(:login_activity) { Fabricate :login_activity, user: user } + + context 'when signed in' do + before { sign_in user } + + describe 'Viewing the login activities page' do + it 'shows the login activity history' do + visit edit_user_registration_path + + click_on I18n.t('sessions.view_authentication_history') + + expect(page) + .to have_content(browser_description) + .and have_content(login_activity.authentication_method) + .and have_content(login_activity.ip) + .and have_private_cache_control + end + + def browser_description + I18n.t( + 'sessions.description', + browser: I18n.t("sessions.browsers.#{login_activity.browser}", default: login_activity.browser), + platform: I18n.t("sessions.platforms.#{login_activity.platform}", default: login_activity.platform) + ) + end + end + end +end