From a1865b6636758ac8ad18f5f165a3ad9700b31807 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Fri, 21 Feb 2025 12:52:01 -0500 Subject: [PATCH] Convert `admin/terms_of_service/*` spec controller->system --- .../distributions_controller_spec.rb | 22 ------- .../drafts_controller_spec.rb | 66 ------------------- .../generates_controller_spec.rb | 66 ------------------- .../previews_controller_spec.rb | 22 ------- .../terms_of_service/tests_controller_spec.rb | 22 ------- .../admin/terms_of_service_controller_spec.rb | 21 ------ .../terms_of_service/distributions_spec.rb | 28 ++++++++ .../admin/terms_of_service/drafts_spec.rb | 39 +++++++++++ .../admin/terms_of_service/generates_spec.rb | 40 +++++++++++ .../admin/terms_of_service/previews_spec.rb | 18 +++++ .../admin/terms_of_service/tests_spec.rb | 25 +++++++ 11 files changed, 150 insertions(+), 219 deletions(-) delete mode 100644 spec/controllers/admin/terms_of_service/distributions_controller_spec.rb delete mode 100644 spec/controllers/admin/terms_of_service/drafts_controller_spec.rb delete mode 100644 spec/controllers/admin/terms_of_service/generates_controller_spec.rb delete mode 100644 spec/controllers/admin/terms_of_service/previews_controller_spec.rb delete mode 100644 spec/controllers/admin/terms_of_service/tests_controller_spec.rb delete mode 100644 spec/controllers/admin/terms_of_service_controller_spec.rb create mode 100644 spec/system/admin/terms_of_service/distributions_spec.rb create mode 100644 spec/system/admin/terms_of_service/drafts_spec.rb create mode 100644 spec/system/admin/terms_of_service/generates_spec.rb create mode 100644 spec/system/admin/terms_of_service/previews_spec.rb create mode 100644 spec/system/admin/terms_of_service/tests_spec.rb diff --git a/spec/controllers/admin/terms_of_service/distributions_controller_spec.rb b/spec/controllers/admin/terms_of_service/distributions_controller_spec.rb deleted file mode 100644 index 63431c1336..0000000000 --- a/spec/controllers/admin/terms_of_service/distributions_controller_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -RSpec.describe Admin::TermsOfService::DistributionsController do - render_views - - let(:user) { Fabricate(:admin_user) } - let(:terms_of_service) { Fabricate(:terms_of_service, notification_sent_at: nil) } - - before do - sign_in user, scope: :user - end - - describe 'POST #create' do - it 'returns http success' do - post :create, params: { terms_of_service_id: terms_of_service.id } - - expect(response).to redirect_to(admin_terms_of_service_index_path) - end - end -end diff --git a/spec/controllers/admin/terms_of_service/drafts_controller_spec.rb b/spec/controllers/admin/terms_of_service/drafts_controller_spec.rb deleted file mode 100644 index 0a9c6e6b67..0000000000 --- a/spec/controllers/admin/terms_of_service/drafts_controller_spec.rb +++ /dev/null @@ -1,66 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -RSpec.describe Admin::TermsOfService::DraftsController do - render_views - - let(:user) { Fabricate(:admin_user) } - - before do - sign_in user, scope: :user - end - - describe 'GET #show' do - it 'returns http success' do - get :show - - expect(response).to have_http_status(:success) - end - end - - describe 'PUT #update' do - subject { put :update, params: params } - - let!(:terms) { Fabricate :terms_of_service, published_at: nil } - - context 'with publishing params' do - let(:params) { { terms_of_service: { text: 'new' }, action_type: 'publish' } } - - it 'publishes the record' do - expect { subject } - .to change(Admin::ActionLog, :count).by(1) - - expect(response) - .to redirect_to(admin_terms_of_service_index_path) - expect(terms.reload.published_at) - .to_not be_nil - end - end - - context 'with non publishing params' do - let(:params) { { terms_of_service: { text: 'new' }, action_type: 'save_draft' } } - - it 'updates but does not publish the record' do - expect { subject } - .to_not change(Admin::ActionLog, :count) - - expect(response) - .to redirect_to(admin_terms_of_service_draft_path) - expect(terms.reload.published_at) - .to be_nil - end - end - - context 'with invalid params' do - let(:params) { { terms_of_service: { text: '' }, action_type: 'save_draft' } } - - it 'does not update the record' do - subject - - expect(response) - .to have_http_status(:success) - end - end - end -end diff --git a/spec/controllers/admin/terms_of_service/generates_controller_spec.rb b/spec/controllers/admin/terms_of_service/generates_controller_spec.rb deleted file mode 100644 index b528bfb57a..0000000000 --- a/spec/controllers/admin/terms_of_service/generates_controller_spec.rb +++ /dev/null @@ -1,66 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -RSpec.describe Admin::TermsOfService::GeneratesController do - render_views - - let(:user) { Fabricate(:admin_user) } - - before do - sign_in user, scope: :user - end - - describe 'GET #show' do - it 'returns http success' do - get :show - - expect(response).to have_http_status(:success) - end - end - - describe 'POST #create' do - subject { post :create, params: params } - - context 'with valid params' do - let(:params) do - { - terms_of_service_generator: { - admin_email: 'test@host.example', - arbitration_address: '123 Main Street', - arbitration_website: 'https://host.example', - dmca_address: '123 DMCA Ave', - dmca_email: 'dmca@host.example', - domain: 'host.example', - jurisdiction: 'Europe', - choice_of_law: 'New York', - }, - } - end - - it 'saves new record' do - expect { subject } - .to change(TermsOfService, :count).by(1) - expect(response) - .to redirect_to(admin_terms_of_service_draft_path) - end - end - - context 'with invalid params' do - let(:params) do - { - terms_of_service_generator: { - admin_email: 'what the', - }, - } - end - - it 'does not save new record' do - expect { subject } - .to_not change(TermsOfService, :count) - expect(response) - .to have_http_status(200) - end - end - end -end diff --git a/spec/controllers/admin/terms_of_service/previews_controller_spec.rb b/spec/controllers/admin/terms_of_service/previews_controller_spec.rb deleted file mode 100644 index 3878bb4b6f..0000000000 --- a/spec/controllers/admin/terms_of_service/previews_controller_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -RSpec.describe Admin::TermsOfService::PreviewsController do - render_views - - let(:user) { Fabricate(:admin_user) } - let(:terms_of_service) { Fabricate(:terms_of_service, notification_sent_at: nil) } - - before do - sign_in user, scope: :user - end - - describe 'GET #show' do - it 'returns http success' do - get :show, params: { terms_of_service_id: terms_of_service.id } - - expect(response).to have_http_status(:success) - end - end -end diff --git a/spec/controllers/admin/terms_of_service/tests_controller_spec.rb b/spec/controllers/admin/terms_of_service/tests_controller_spec.rb deleted file mode 100644 index 777f699448..0000000000 --- a/spec/controllers/admin/terms_of_service/tests_controller_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -RSpec.describe Admin::TermsOfService::TestsController do - render_views - - let(:user) { Fabricate(:admin_user) } - let(:terms_of_service) { Fabricate(:terms_of_service, notification_sent_at: nil) } - - before do - sign_in user, scope: :user - end - - describe 'POST #create' do - it 'returns http success' do - post :create, params: { terms_of_service_id: terms_of_service.id } - - expect(response).to redirect_to(admin_terms_of_service_preview_path(terms_of_service)) - end - end -end diff --git a/spec/controllers/admin/terms_of_service_controller_spec.rb b/spec/controllers/admin/terms_of_service_controller_spec.rb deleted file mode 100644 index feefd312e3..0000000000 --- a/spec/controllers/admin/terms_of_service_controller_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -RSpec.describe Admin::TermsOfServiceController do - render_views - - let(:user) { Fabricate(:admin_user) } - - before do - sign_in user, scope: :user - end - - describe 'GET #index' do - it 'returns http success' do - get :index - - expect(response).to have_http_status(:success) - end - end -end diff --git a/spec/system/admin/terms_of_service/distributions_spec.rb b/spec/system/admin/terms_of_service/distributions_spec.rb new file mode 100644 index 0000000000..c85494728c --- /dev/null +++ b/spec/system/admin/terms_of_service/distributions_spec.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe 'Admin TermsOfService Distributions' do + let(:user) { Fabricate(:admin_user) } + let(:terms_of_service) { Fabricate(:terms_of_service, notification_sent_at: nil) } + + before { sign_in(user) } + + describe 'Sending test TOS email', :inline_jobs do + it 'generates the test email' do + visit admin_terms_of_service_preview_path(terms_of_service) + expect(page) + .to have_title(I18n.t('admin.terms_of_service.preview.title')) + + emails = capture_emails do + expect { click_on I18n.t('admin.terms_of_service.preview.send_to_all', count: 1, display_count: 1) } + .to(change { terms_of_service.reload.notification_sent_at }) + end + expect(emails.first) + .to be_present + .and(deliver_to(user.email)) + expect(page) + .to have_title(I18n.t('admin.terms_of_service.title')) + end + end +end diff --git a/spec/system/admin/terms_of_service/drafts_spec.rb b/spec/system/admin/terms_of_service/drafts_spec.rb new file mode 100644 index 0000000000..3c272694cb --- /dev/null +++ b/spec/system/admin/terms_of_service/drafts_spec.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe 'Admin TermsOfService Drafts' do + before { sign_in(admin_user) } + + describe 'Managing TOS drafts' do + let!(:terms) { Fabricate :terms_of_service, published_at: nil } + + it 'saves and publishes TOS drafts' do + visit admin_terms_of_service_draft_path + expect(page) + .to have_title(I18n.t('admin.terms_of_service.title')) + + # Invalid submission + expect { click_on I18n.t('admin.terms_of_service.save_draft') } + .to_not(change { terms.reload.published_at }) + expect(page) + .to have_title(I18n.t('admin.terms_of_service.title')) + + # Valid submission with draft button + fill_in 'terms_of_service_text', with: 'new' + expect { click_on I18n.t('admin.terms_of_service.save_draft') } + .to not_change { terms.reload.published_at }.from(nil) + .and not_change(Admin::ActionLog, :count) + expect(page) + .to have_title(I18n.t('admin.terms_of_service.title')) + + # Valid with publish button + fill_in 'terms_of_service_text', with: 'newer' + expect { click_on I18n.t('admin.terms_of_service.publish') } + .to change { terms.reload.published_at }.from(nil) + .and change(Admin::ActionLog, :count) + expect(page) + .to have_title(I18n.t('admin.terms_of_service.title')) + end + end +end diff --git a/spec/system/admin/terms_of_service/generates_spec.rb b/spec/system/admin/terms_of_service/generates_spec.rb new file mode 100644 index 0000000000..2307d245b0 --- /dev/null +++ b/spec/system/admin/terms_of_service/generates_spec.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe 'Admin TermsOfService Generates' do + before { sign_in(admin_user) } + + describe 'Generating a TOS policy' do + it 'saves a new TOS from values' do + visit admin_terms_of_service_generate_path + expect(page) + .to have_title(I18n.t('admin.terms_of_service.generates.title')) + + # Invalid form submission + fill_in 'terms_of_service_generator_admin_email', with: 'what the' + expect { submit_form } + .to_not change(TermsOfService, :count) + expect(page) + .to have_title(I18n.t('admin.terms_of_service.generates.title')) + + # Valid submission + fill_in 'terms_of_service_generator_admin_email', with: 'test@host.example' + fill_in 'terms_of_service_generator_arbitration_address', with: '123 Main Street' + fill_in 'terms_of_service_generator_arbitration_website', with: 'https://host.example' + fill_in 'terms_of_service_generator_dmca_address', with: '123 DMCA Ave' + fill_in 'terms_of_service_generator_dmca_email', with: 'dmca@host.example' + fill_in 'terms_of_service_generator_domain', with: 'host.example' + fill_in 'terms_of_service_generator_jurisdiction', with: 'Europe' + fill_in 'terms_of_service_generator_choice_of_law', with: 'New York' + expect { submit_form } + .to change(TermsOfService, :count).by(1) + expect(page) + .to have_title(I18n.t('admin.terms_of_service.title')) + end + + def submit_form + click_on I18n.t('admin.terms_of_service.generates.action') + end + end +end diff --git a/spec/system/admin/terms_of_service/previews_spec.rb b/spec/system/admin/terms_of_service/previews_spec.rb new file mode 100644 index 0000000000..f6030c62a9 --- /dev/null +++ b/spec/system/admin/terms_of_service/previews_spec.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe 'Admin TermsOfService Previews' do + let(:terms_of_service) { Fabricate(:terms_of_service, notification_sent_at: nil) } + + before { sign_in(admin_user) } + + describe 'Viewing TOS previews' do + it 'shows the TOS preview page' do + visit admin_terms_of_service_preview_path(terms_of_service) + + expect(page) + .to have_title(I18n.t('admin.terms_of_service.preview.title')) + end + end +end diff --git a/spec/system/admin/terms_of_service/tests_spec.rb b/spec/system/admin/terms_of_service/tests_spec.rb new file mode 100644 index 0000000000..3fc7d4e75d --- /dev/null +++ b/spec/system/admin/terms_of_service/tests_spec.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe 'Admin TermsOfService Tests' do + let(:user) { Fabricate(:admin_user) } + let(:terms_of_service) { Fabricate(:terms_of_service, notification_sent_at: nil) } + + before { sign_in(user) } + + describe 'Sending test TOS email', :inline_jobs do + it 'generates the test email' do + visit admin_terms_of_service_preview_path(terms_of_service) + expect(page) + .to have_title(I18n.t('admin.terms_of_service.preview.title')) + + emails = capture_emails { click_on I18n.t('admin.terms_of_service.preview.send_preview', email: user.email) } + expect(emails.first) + .to be_present + .and(deliver_to(user.email)) + expect(page) + .to have_title(I18n.t('admin.terms_of_service.preview.title')) + end + end +end