Convert `settings/migration/redirects` spec controller->system (#33905)
parent
db59f37269
commit
b07cd11f4c
|
@ -1,67 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Settings::Migration::RedirectsController do
|
||||
render_views
|
||||
|
||||
let!(:user) { Fabricate(:user, password: 'testtest') }
|
||||
|
||||
before do
|
||||
sign_in user, scope: :user
|
||||
end
|
||||
|
||||
describe 'GET #new' do
|
||||
before do
|
||||
get :new
|
||||
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
|
||||
|
||||
describe 'POST #create' do
|
||||
context 'with valid params' do
|
||||
before { stub_resolver }
|
||||
|
||||
it 'redirects to the settings migration path' do
|
||||
post :create, params: { form_redirect: { acct: 'new@host.com', current_password: 'testtest' } }
|
||||
|
||||
expect(response).to redirect_to(settings_migration_path)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with non valid params' do
|
||||
it 'returns success and renders the new page' do
|
||||
post :create, params: { form_redirect: { acct: '' } }
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response).to render_template(:new)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE #destroy' do
|
||||
let(:account) { Fabricate(:account) }
|
||||
|
||||
before do
|
||||
user.account.update(moved_to_account_id: account.id)
|
||||
end
|
||||
|
||||
it 'resets the account and sends an update' do
|
||||
delete :destroy
|
||||
|
||||
expect(response).to redirect_to(settings_migration_path)
|
||||
expect(user.account.reload.moved_to_account).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def stub_resolver
|
||||
resolver = instance_double(ResolveAccountService, call: Fabricate(:account))
|
||||
allow(ResolveAccountService).to receive(:new).and_return(resolver)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,42 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Settings Migration Redirects' do
|
||||
let!(:user) { Fabricate(:user, password: 'testtest') }
|
||||
|
||||
before { sign_in(user) }
|
||||
|
||||
describe 'Managing redirects' do
|
||||
before { stub_resolver }
|
||||
|
||||
it 'creates and destroys redirects' do
|
||||
visit new_settings_migration_redirect_path
|
||||
expect(page)
|
||||
.to have_title(I18n.t('settings.migrate'))
|
||||
|
||||
# Empty form invalid submission
|
||||
expect { click_on I18n.t('migrations.set_redirect') }
|
||||
.to_not(change { user.account.moved_to_account_id }.from(nil))
|
||||
|
||||
# Valid form submission
|
||||
fill_in 'form_redirect_acct', with: 'new@example.host'
|
||||
fill_in 'form_redirect_current_password', with: 'testtest'
|
||||
expect { click_on I18n.t('migrations.set_redirect') }
|
||||
.to(change { user.reload.account.moved_to_account_id }.from(nil))
|
||||
|
||||
# Delete the account move
|
||||
expect { click_on I18n.t('migrations.cancel') }
|
||||
.to(change { user.reload.account.moved_to_account_id }.to(nil))
|
||||
expect(page)
|
||||
.to have_content(I18n.t('migrations.cancelled_msg'))
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def stub_resolver
|
||||
resolver = instance_double(ResolveAccountService, call: Fabricate(:account))
|
||||
allow(ResolveAccountService).to receive(:new).and_return(resolver)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue