mastodon/spec/system/settings/migrations_spec.rb
Matt Jankowski 696aaa616b
Some checks failed
Check i18n / check-i18n (push) Waiting to run
Chromatic / Check for relevant changes (push) Waiting to run
Chromatic / Run Chromatic (push) Blocked by required conditions
Check formatting / lint (push) Waiting to run
CSS Linting / lint (push) Waiting to run
Haml Linting / lint (push) Waiting to run
JavaScript Linting / lint (push) Waiting to run
Ruby Linting / lint (push) Waiting to run
JavaScript Testing / test (push) Waiting to run
Historical data migration test / test (14-alpine) (push) Waiting to run
Historical data migration test / test (15-alpine) (push) Waiting to run
Historical data migration test / test (16-alpine) (push) Waiting to run
Historical data migration test / test (17-alpine) (push) Waiting to run
Ruby Testing / build (production) (push) Waiting to run
Ruby Testing / build (test) (push) Waiting to run
Ruby Testing / test (.ruby-version) (push) Blocked by required conditions
Ruby Testing / test (3.3) (push) Blocked by required conditions
Ruby Testing / test (3.4) (push) Blocked by required conditions
Ruby Testing / End to End testing (.ruby-version) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.3) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.4) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.19.2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.3, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.4, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Blocked by required conditions
Bundler Audit / security (push) Has been cancelled
CodeQL / Analyze (actions) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
CodeQL / Analyze (ruby) (push) Has been cancelled
Update rubocop-capybara to version 2.23.0 (#38868)
2026-05-04 07:52:29 +00:00

126 lines
3.8 KiB
Ruby

# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'Settings Migrations' do
describe 'Viewing settings migrations' do
let(:user) { Fabricate(:account, moved_to_account: moved_to_account).user }
before { sign_in(user) }
context 'when user does not have moved to account' do
let(:moved_to_account) { nil }
it 'renders show page' do
visit settings_migration_path
expect(page)
.to have_text(I18n.t('settings.migrate'))
end
end
context 'when user has a moved to account' do
let(:moved_to_account) { Fabricate(:account) }
it 'renders show page and account details' do
visit settings_migration_path
expect(page)
.to have_text(I18n.t('settings.migrate'))
.and have_text(moved_to_account.pretty_acct)
end
end
end
describe 'Creating migrations' do
let(:user) { Fabricate(:user, password:) }
let(:password) { '12345678' }
before { sign_in(user) }
context 'when migration account is changed' do
let(:acct) { Fabricate(:account, also_known_as: [ActivityPub::TagManager.instance.uri_for(user.account)]) }
context 'when user has encrypted password' do
it 'updates moved to account' do
visit settings_migration_path
expect { fill_in_and_submit }
.to(change { user.account.reload.moved_to_account_id }.to(acct.id))
expect(page)
.to have_text(I18n.t('settings.migrate'))
end
end
context 'when user has blank encrypted password value' do
before { user.update! encrypted_password: '' }
it 'updates moved to account using at-username value' do
visit settings_migration_path
expect { fill_in_and_submit_via_username("@#{user.account.username}") }
.to(change { user.account.reload.moved_to_account_id }.to(acct.id))
expect(page)
.to have_text(I18n.t('settings.migrate'))
end
end
end
context 'when acct is the current account' do
let(:acct) { user.account }
it 'does not update the moved account', :aggregate_failures do
visit settings_migration_path
expect { fill_in_and_submit }
.to_not(change { user.account.reload.moved_to_account_id }.from(nil))
expect(page)
.to have_text(I18n.t('settings.migrate'))
end
end
context 'when target account does not reference the account being moved from' do
let(:acct) { Fabricate(:account, also_known_as: []) }
it 'does not update the moved account', :aggregate_failures do
visit settings_migration_path
expect { fill_in_and_submit }
.to_not(change { user.account.reload.moved_to_account_id }.from(nil))
expect(page)
.to have_text(I18n.t('settings.migrate'))
end
end
context 'when a recent migration already exists' do
let(:acct) { Fabricate(:account, also_known_as: [ActivityPub::TagManager.instance.uri_for(user.account)]) }
let(:moved_to) { Fabricate(:account, also_known_as: [ActivityPub::TagManager.instance.uri_for(user.account)]) }
before { user.account.migrations.create!(acct: moved_to.acct) }
it 'can not update the moved account', :aggregate_failures do
visit settings_migration_path
expect(find_by_id('account_migration_acct'))
.to be_disabled
end
end
def fill_in_and_submit
fill_in 'account_migration_acct', with: acct.username
if block_given?
yield
else
fill_in 'account_migration_current_password', with: password
end
click_on I18n.t('migrations.proceed_with_move')
end
def fill_in_and_submit_via_username(username)
fill_in_and_submit do
fill_in 'account_migration_current_username', with: username
end
end
end
end