mirror of
https://git.kescher.at/CatCatNya/catstodon.git
synced 2024-11-22 11:48:06 +01:00
Add coverage to CLI Maintenance for duplicate users on confirmation_token
and reset_password_token
values (#28434)
This commit is contained in:
parent
6fed0fcbaa
commit
961d65aba6
1 changed files with 59 additions and 1 deletions
|
@ -89,7 +89,7 @@ describe Mastodon::CLI::Maintenance do
|
|||
end
|
||||
end
|
||||
|
||||
context 'with duplicate users' do
|
||||
context 'with duplicate users on email' do
|
||||
before do
|
||||
prepare_duplicate_data
|
||||
end
|
||||
|
@ -117,6 +117,64 @@ describe Mastodon::CLI::Maintenance do
|
|||
end
|
||||
end
|
||||
|
||||
context 'with duplicate users on confirmation_token' do
|
||||
before do
|
||||
prepare_duplicate_data
|
||||
end
|
||||
|
||||
let(:duplicate_confirmation_token) { '123ABC' }
|
||||
|
||||
it 'runs the deduplication process' do
|
||||
expect { subject }
|
||||
.to output_results(
|
||||
'Deduplicating user records',
|
||||
'Unsetting confirmation token',
|
||||
'Restoring users indexes',
|
||||
'Finished!'
|
||||
)
|
||||
.and change(duplicate_users, :count).from(2).to(1)
|
||||
end
|
||||
|
||||
def duplicate_users
|
||||
User.where(confirmation_token: duplicate_confirmation_token)
|
||||
end
|
||||
|
||||
def prepare_duplicate_data
|
||||
ActiveRecord::Base.connection.remove_index :users, :confirmation_token
|
||||
Fabricate(:user, confirmation_token: duplicate_confirmation_token)
|
||||
Fabricate.build(:user, confirmation_token: duplicate_confirmation_token).save(validate: false)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with duplicate users on reset_password_token' do
|
||||
before do
|
||||
prepare_duplicate_data
|
||||
end
|
||||
|
||||
let(:duplicate_reset_password_token) { '123ABC' }
|
||||
|
||||
it 'runs the deduplication process' do
|
||||
expect { subject }
|
||||
.to output_results(
|
||||
'Deduplicating user records',
|
||||
'Unsetting password reset token',
|
||||
'Restoring users indexes',
|
||||
'Finished!'
|
||||
)
|
||||
.and change(duplicate_users, :count).from(2).to(1)
|
||||
end
|
||||
|
||||
def duplicate_users
|
||||
User.where(reset_password_token: duplicate_reset_password_token)
|
||||
end
|
||||
|
||||
def prepare_duplicate_data
|
||||
ActiveRecord::Base.connection.remove_index :users, :reset_password_token
|
||||
Fabricate(:user, reset_password_token: duplicate_reset_password_token)
|
||||
Fabricate.build(:user, reset_password_token: duplicate_reset_password_token).save(validate: false)
|
||||
end
|
||||
end
|
||||
|
||||
def agree_to_backup_warning
|
||||
allow(cli.shell)
|
||||
.to receive(:yes?)
|
||||
|
|
Loading…
Reference in a new issue