Add delay to profile updates to debounce them (#34137)
This commit is contained in:
parent
d9fb61f305
commit
6d53e8c6c5
12 changed files with 22 additions and 24 deletions
|
@ -31,7 +31,7 @@ RSpec.describe Settings::PrivacyController do
|
|||
describe 'PUT #update' do
|
||||
context 'when update succeeds' do
|
||||
before do
|
||||
allow(ActivityPub::UpdateDistributionWorker).to receive(:perform_async)
|
||||
allow(ActivityPub::UpdateDistributionWorker).to receive(:perform_in)
|
||||
end
|
||||
|
||||
it 'updates the user profile' do
|
||||
|
@ -44,14 +44,14 @@ RSpec.describe Settings::PrivacyController do
|
|||
.to redirect_to(settings_privacy_path)
|
||||
|
||||
expect(ActivityPub::UpdateDistributionWorker)
|
||||
.to have_received(:perform_async).with(account.id)
|
||||
.to have_received(:perform_in).with(anything, account.id)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when update fails' do
|
||||
before do
|
||||
allow(UpdateAccountService).to receive(:new).and_return(failing_update_service)
|
||||
allow(ActivityPub::UpdateDistributionWorker).to receive(:perform_async)
|
||||
allow(ActivityPub::UpdateDistributionWorker).to receive(:perform_in)
|
||||
end
|
||||
|
||||
it 'updates the user profile' do
|
||||
|
@ -61,7 +61,7 @@ RSpec.describe Settings::PrivacyController do
|
|||
.to render_template(:show)
|
||||
|
||||
expect(ActivityPub::UpdateDistributionWorker)
|
||||
.to_not have_received(:perform_async)
|
||||
.to_not have_received(:perform_in)
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -29,23 +29,23 @@ RSpec.describe Settings::ProfilesController do
|
|||
end
|
||||
|
||||
it 'updates the user profile' do
|
||||
allow(ActivityPub::UpdateDistributionWorker).to receive(:perform_async)
|
||||
allow(ActivityPub::UpdateDistributionWorker).to receive(:perform_in)
|
||||
put :update, params: { account: { display_name: 'New name' } }
|
||||
expect(account.reload.display_name).to eq 'New name'
|
||||
expect(response).to redirect_to(settings_profile_path)
|
||||
expect(ActivityPub::UpdateDistributionWorker).to have_received(:perform_async).with(account.id)
|
||||
expect(ActivityPub::UpdateDistributionWorker).to have_received(:perform_in).with(anything, account.id)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'PUT #update with new profile image' do
|
||||
it 'updates profile image' do
|
||||
allow(ActivityPub::UpdateDistributionWorker).to receive(:perform_async)
|
||||
allow(ActivityPub::UpdateDistributionWorker).to receive(:perform_in)
|
||||
expect(account.avatar.instance.avatar_file_name).to be_nil
|
||||
|
||||
put :update, params: { account: { avatar: fixture_file_upload('avatar.gif', 'image/gif') } }
|
||||
expect(response).to redirect_to(settings_profile_path)
|
||||
expect(account.reload.avatar.instance.avatar_file_name).to_not be_nil
|
||||
expect(ActivityPub::UpdateDistributionWorker).to have_received(:perform_async).with(account.id)
|
||||
expect(ActivityPub::UpdateDistributionWorker).to have_received(:perform_in).with(anything, account.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -53,8 +53,6 @@ RSpec.describe 'credentials API' do
|
|||
patch '/api/v1/accounts/update_credentials', headers: headers, params: params
|
||||
end
|
||||
|
||||
before { allow(ActivityPub::UpdateDistributionWorker).to receive(:perform_async) }
|
||||
|
||||
let(:params) do
|
||||
{
|
||||
avatar: fixture_file_upload('avatar.gif', 'image/gif'),
|
||||
|
@ -112,7 +110,7 @@ RSpec.describe 'credentials API' do
|
|||
})
|
||||
|
||||
expect(ActivityPub::UpdateDistributionWorker)
|
||||
.to have_received(:perform_async).with(user.account_id)
|
||||
.to have_enqueued_sidekiq_job(user.account_id)
|
||||
end
|
||||
|
||||
def expect_account_updates
|
||||
|
|
|
@ -15,10 +15,6 @@ RSpec.describe 'Deleting profile images' do
|
|||
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
|
||||
|
||||
describe 'DELETE /api/v1/profile' do
|
||||
before do
|
||||
allow(ActivityPub::UpdateDistributionWorker).to receive(:perform_async)
|
||||
end
|
||||
|
||||
context 'when deleting an avatar' do
|
||||
context 'with wrong scope' do
|
||||
before do
|
||||
|
@ -38,7 +34,8 @@ RSpec.describe 'Deleting profile images' do
|
|||
account.reload
|
||||
expect(account.avatar).to_not exist
|
||||
expect(account.header).to exist
|
||||
expect(ActivityPub::UpdateDistributionWorker).to have_received(:perform_async).with(account.id)
|
||||
expect(ActivityPub::UpdateDistributionWorker)
|
||||
.to have_enqueued_sidekiq_job(account.id)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -61,7 +58,8 @@ RSpec.describe 'Deleting profile images' do
|
|||
account.reload
|
||||
expect(account.avatar).to exist
|
||||
expect(account.header).to_not exist
|
||||
expect(ActivityPub::UpdateDistributionWorker).to have_received(:perform_async).with(account.id)
|
||||
expect(ActivityPub::UpdateDistributionWorker)
|
||||
.to have_enqueued_sidekiq_job(account.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue