From 5a8f2fe31d15a2a07384d118b5cbcd10ad714be4 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Thu, 19 Sep 2024 09:43:40 -0400 Subject: [PATCH] Convert `settings/exports` controller spec to system/request specs (#31965) --- .../settings/exports_controller_spec.rb | 47 ------------------- spec/requests/settings/exports_spec.rb | 25 ++++++++++ spec/system/settings/exports_spec.rb | 40 ++++++++++++++++ 3 files changed, 65 insertions(+), 47 deletions(-) delete mode 100644 spec/controllers/settings/exports_controller_spec.rb create mode 100644 spec/requests/settings/exports_spec.rb create mode 100644 spec/system/settings/exports_spec.rb diff --git a/spec/controllers/settings/exports_controller_spec.rb b/spec/controllers/settings/exports_controller_spec.rb deleted file mode 100644 index 1eafabc7e..000000000 --- a/spec/controllers/settings/exports_controller_spec.rb +++ /dev/null @@ -1,47 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -RSpec.describe Settings::ExportsController do - render_views - - describe 'GET #show' do - context 'when signed in' do - let(:user) { Fabricate(:user) } - - before do - sign_in user, scope: :user - get :show - 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') - end - end - - context 'when not signed in' do - it 'redirects' do - get :show - expect(response).to redirect_to '/auth/sign_in' - end - end - end - - describe 'POST #create' do - before do - sign_in Fabricate(:user), scope: :user - end - - it 'redirects to settings_export_path' do - post :create - expect(response).to redirect_to(settings_export_path) - end - - it 'queues BackupWorker job by 1' do - expect do - post :create - end.to change(BackupWorker.jobs, :size).by(1) - end - end -end diff --git a/spec/requests/settings/exports_spec.rb b/spec/requests/settings/exports_spec.rb new file mode 100644 index 000000000..db823ac77 --- /dev/null +++ b/spec/requests/settings/exports_spec.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe 'Settings / Exports' do + context 'when not signed in' do + describe 'GET /settings/export' do + it 'redirects to sign in page' do + get settings_export_path + + expect(response) + .to redirect_to new_user_session_path + end + end + + describe 'POST /settings/export' do + it 'redirects to sign in page' do + post settings_export_path + + expect(response) + .to redirect_to new_user_session_path + end + end + end +end diff --git a/spec/system/settings/exports_spec.rb b/spec/system/settings/exports_spec.rb new file mode 100644 index 000000000..2cc2961a0 --- /dev/null +++ b/spec/system/settings/exports_spec.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe 'Export page' do + let(:user) { Fabricate :user } + + before { sign_in user } + + describe 'Viewing the export page' do + context 'when signed in' do + it 'shows the export page', :aggregate_failures do + visit settings_export_path + + expect(page) + .to have_content(takeout_summary) + .and have_private_cache_control + end + end + end + + describe 'Creating a new archive' do + it 'queues a worker and redirects' do + visit settings_export_path + + expect { request_archive } + .to change(BackupWorker.jobs, :size).by(1) + expect(page) + .to have_content(takeout_summary) + end + + def request_archive + click_on I18n.t('exports.archive_takeout.request') + end + end + + def takeout_summary + I18n.t('settings.export') + end +end