2023-02-22 01:55:31 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-06-02 11:52:16 +02:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2024-09-04 07:12:25 +02:00
|
|
|
RSpec.describe Settings::MigrationsController do
|
2018-06-02 11:52:16 +02:00
|
|
|
render_views
|
|
|
|
|
|
|
|
describe 'GET #show' do
|
|
|
|
context 'when user is not sign in' do
|
|
|
|
subject { get :show }
|
|
|
|
|
2024-09-25 09:50:15 +02:00
|
|
|
it { is_expected.to redirect_to new_user_session_path }
|
2018-06-02 11:52:16 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is sign in' do
|
|
|
|
subject { get :show }
|
|
|
|
|
2022-01-28 00:46:42 +01:00
|
|
|
let(:user) { Fabricate(:account, moved_to_account: moved_to_account).user }
|
2019-09-19 20:58:19 +02:00
|
|
|
|
2018-06-02 11:52:16 +02: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
|
2023-02-20 05:00:48 +01:00
|
|
|
expect(subject).to have_http_status 200
|
|
|
|
expect(subject).to render_template :show
|
2018-06-02 11:52:16 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-19 20:58:19 +02:00
|
|
|
context 'when user has a moved to account' do
|
2018-06-02 11:52:16 +02:00
|
|
|
let(:moved_to_account) { Fabricate(:account) }
|
|
|
|
|
|
|
|
it 'renders show page' do
|
2023-02-20 05:00:48 +01:00
|
|
|
expect(subject).to have_http_status 200
|
|
|
|
expect(subject).to render_template :show
|
2018-06-02 11:52:16 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-19 20:58:19 +02:00
|
|
|
describe 'POST #create' do
|
2018-06-02 11:52:16 +02:00
|
|
|
context 'when user is not sign in' do
|
2019-09-19 20:58:19 +02:00
|
|
|
subject { post :create }
|
2018-06-02 11:52:16 +02:00
|
|
|
|
2024-09-25 09:50:15 +02:00
|
|
|
it { is_expected.to redirect_to new_user_session_path }
|
2018-06-02 11:52:16 +02:00
|
|
|
end
|
|
|
|
|
2021-02-02 14:49:57 +01:00
|
|
|
context 'when user is signed in' do
|
2019-09-19 20:58:19 +02:00
|
|
|
subject { post :create, params: { account_migration: { acct: acct, current_password: '12345678' } } }
|
|
|
|
|
|
|
|
let(:user) { Fabricate(:user, password: '12345678') }
|
2018-06-02 11:52:16 +02:00
|
|
|
|
|
|
|
before { sign_in user, scope: :user }
|
|
|
|
|
|
|
|
context 'when migration account is changed' do
|
2019-09-19 20:58:19 +02:00
|
|
|
let(:acct) { Fabricate(:account, also_known_as: [ActivityPub::TagManager.instance.uri_for(user.account)]) }
|
2018-06-02 11:52:16 +02:00
|
|
|
|
|
|
|
it 'updates moved to account' do
|
2023-02-20 05:00:48 +01:00
|
|
|
expect(subject).to redirect_to settings_migration_path
|
2018-06-02 11:52:16 +02:00
|
|
|
expect(user.account.reload.moved_to_account_id).to eq acct.id
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-02-02 14:49:57 +01:00
|
|
|
context 'when acct is the current account' do
|
2018-06-02 11:52:16 +02:00
|
|
|
let(:acct) { user.account }
|
|
|
|
|
2023-11-10 16:13:42 +01:00
|
|
|
it 'does not update the moved account', :aggregate_failures do
|
|
|
|
subject
|
2021-02-02 14:49:57 +01:00
|
|
|
|
|
|
|
expect(user.account.reload.moved_to_account_id).to be_nil
|
2023-11-10 16:13:42 +01:00
|
|
|
expect(response).to render_template :show
|
2021-02-02 14:49:57 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when target account does not reference the account being moved from' do
|
|
|
|
let(:acct) { Fabricate(:account, also_known_as: []) }
|
|
|
|
|
2023-11-10 16:13:42 +01:00
|
|
|
it 'does not update the moved account', :aggregate_failures do
|
|
|
|
subject
|
2021-02-02 14:49:57 +01:00
|
|
|
|
|
|
|
expect(user.account.reload.moved_to_account_id).to be_nil
|
2023-11-10 16:13:42 +01:00
|
|
|
expect(response).to render_template :show
|
2021-02-02 14:49:57 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-02-18 12:47:37 +01:00
|
|
|
context 'when a recent migration already exists' do
|
2021-02-02 14:49:57 +01: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
|
|
|
|
|
2023-11-10 16:13:42 +01:00
|
|
|
it 'does not update the moved account', :aggregate_failures do
|
|
|
|
subject
|
2021-02-02 14:49:57 +01:00
|
|
|
|
|
|
|
expect(user.account.reload.moved_to_account_id).to be_nil
|
2023-11-10 16:13:42 +01:00
|
|
|
expect(response).to render_template :show
|
2021-02-02 14:49:57 +01:00
|
|
|
end
|
2018-06-02 11:52:16 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|