Convert `admin/terms_of_service/*` spec controller->system

pull/33975/head
Matt Jankowski 1 week ago
parent 33643c4c07
commit a1865b6636

@ -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

@ -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

@ -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

@ -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

@ -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

@ -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

@ -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

@ -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

@ -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

@ -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

@ -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
Loading…
Cancel
Save