2018-06-02 19:52:16 +10:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe Settings::MigrationsController do
|
|
|
|
render_views
|
|
|
|
|
|
|
|
shared_examples 'authenticate user' do
|
|
|
|
it 'redirects to sign_in page' do
|
|
|
|
is_expected.to redirect_to new_user_session_path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #show' do
|
|
|
|
context 'when user is not sign in' do
|
|
|
|
subject { get :show }
|
|
|
|
|
|
|
|
it_behaves_like 'authenticate user'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is sign in' do
|
|
|
|
subject { get :show }
|
|
|
|
|
2022-01-28 10:46:42 +11:00
|
|
|
let(:user) { Fabricate(:account, moved_to_account: moved_to_account).user }
|
2019-09-20 04:58:19 +10:00
|
|
|
|
2018-06-02 19:52:16 +10:00
|
|
|
before { sign_in user, scope: :user }
|
|
|
|
|
|
|
|
context 'when user does not have moved to account' do
|
|
|
|
let(:moved_to_account) { nil }
|
|
|
|
|
|
|
|
it 'renders show page' do
|
|
|
|
is_expected.to have_http_status 200
|
|
|
|
is_expected.to render_template :show
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-20 04:58:19 +10:00
|
|
|
context 'when user has a moved to account' do
|
2018-06-02 19:52:16 +10:00
|
|
|
let(:moved_to_account) { Fabricate(:account) }
|
|
|
|
|
|
|
|
it 'renders show page' do
|
|
|
|
is_expected.to have_http_status 200
|
|
|
|
is_expected.to render_template :show
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-20 04:58:19 +10:00
|
|
|
describe 'POST #create' do
|
2018-06-02 19:52:16 +10:00
|
|
|
context 'when user is not sign in' do
|
2019-09-20 04:58:19 +10:00
|
|
|
subject { post :create }
|
2018-06-02 19:52:16 +10:00
|
|
|
|
|
|
|
it_behaves_like 'authenticate user'
|
|
|
|
end
|
|
|
|
|
2021-02-03 00:49:57 +11:00
|
|
|
context 'when user is signed in' do
|
2019-09-20 04:58:19 +10:00
|
|
|
subject { post :create, params: { account_migration: { acct: acct, current_password: '12345678' } } }
|
|
|
|
|
|
|
|
let(:user) { Fabricate(:user, password: '12345678') }
|
2018-06-02 19:52:16 +10:00
|
|
|
|
|
|
|
before { sign_in user, scope: :user }
|
|
|
|
|
|
|
|
context 'when migration account is changed' do
|
2019-09-20 04:58:19 +10:00
|
|
|
let(:acct) { Fabricate(:account, also_known_as: [ActivityPub::TagManager.instance.uri_for(user.account)]) }
|
2018-06-02 19:52:16 +10:00
|
|
|
|
|
|
|
it 'updates moved to account' do
|
|
|
|
is_expected.to redirect_to settings_migration_path
|
|
|
|
expect(user.account.reload.moved_to_account_id).to eq acct.id
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-02-03 00:49:57 +11:00
|
|
|
context 'when acct is the current account' do
|
2018-06-02 19:52:16 +10:00
|
|
|
let(:acct) { user.account }
|
|
|
|
|
|
|
|
it 'renders show' do
|
|
|
|
is_expected.to render_template :show
|
|
|
|
end
|
2021-02-03 00:49:57 +11:00
|
|
|
|
|
|
|
it 'does not update the moved account' do
|
|
|
|
expect(user.account.reload.moved_to_account_id).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when target account does not reference the account being moved from' do
|
|
|
|
let(:acct) { Fabricate(:account, also_known_as: []) }
|
|
|
|
|
|
|
|
it 'renders show' do
|
|
|
|
is_expected.to render_template :show
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not update the moved account' do
|
|
|
|
expect(user.account.reload.moved_to_account_id).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-02-18 22:47:37 +11:00
|
|
|
context 'when a recent migration already exists' do
|
2021-02-03 00:49:57 +11:00
|
|
|
let(:acct) { Fabricate(:account, also_known_as: [ActivityPub::TagManager.instance.uri_for(user.account)]) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
moved_to = Fabricate(:account, also_known_as: [ActivityPub::TagManager.instance.uri_for(user.account)])
|
|
|
|
user.account.migrations.create!(acct: moved_to.acct)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders show' do
|
|
|
|
is_expected.to render_template :show
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not update the moved account' do
|
|
|
|
expect(user.account.reload.moved_to_account_id).to be_nil
|
|
|
|
end
|
2018-06-02 19:52:16 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|