mirror of
https://github.com/yingziwu/mastodon.git
synced 2026-02-20 17:23:17 +00:00
Add delay to profile updates to debounce them (#34137)
This commit is contained in:
parent
483b4600b5
commit
91ef24d0e3
12 changed files with 127 additions and 26 deletions
|
|
@ -27,7 +27,7 @@ describe Api::V1::Accounts::CredentialsController do
|
|||
|
||||
describe 'with valid data' do
|
||||
before do
|
||||
allow(ActivityPub::UpdateDistributionWorker).to receive(:perform_async)
|
||||
allow(ActivityPub::UpdateDistributionWorker).to receive(:perform_in)
|
||||
|
||||
patch :update, params: {
|
||||
display_name: "Alice Isn't Dead",
|
||||
|
|
@ -58,7 +58,7 @@ describe Api::V1::Accounts::CredentialsController do
|
|||
end
|
||||
|
||||
it 'queues up an account update distribution' do
|
||||
expect(ActivityPub::UpdateDistributionWorker).to have_received(:perform_async).with(user.account_id)
|
||||
expect(ActivityPub::UpdateDistributionWorker).to have_received(:perform_in).with(anything, user.account_id)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
70
spec/controllers/settings/privacy_controller_spec.rb
Normal file
70
spec/controllers/settings/privacy_controller_spec.rb
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Settings::PrivacyController do
|
||||
render_views
|
||||
|
||||
let!(:user) { Fabricate(:user) }
|
||||
let(:account) { user.account }
|
||||
|
||||
before do
|
||||
sign_in user, scope: :user
|
||||
end
|
||||
|
||||
describe 'GET #show' do
|
||||
before do
|
||||
get :show
|
||||
end
|
||||
|
||||
it 'returns http success with private cache control headers', :aggregate_failures do
|
||||
expect(response)
|
||||
.to have_http_status(200)
|
||||
expect(response.headers['Cache-Control']).to include('private, no-store')
|
||||
end
|
||||
end
|
||||
|
||||
describe 'PUT #update' do
|
||||
context 'when update succeeds' do
|
||||
before do
|
||||
allow(ActivityPub::UpdateDistributionWorker).to receive(:perform_in)
|
||||
end
|
||||
|
||||
it 'updates the user profile' do
|
||||
put :update, params: { account: { discoverable: '1', settings: { indexable: '1' } } }
|
||||
|
||||
expect(account.reload.discoverable)
|
||||
.to be(true)
|
||||
|
||||
expect(response)
|
||||
.to redirect_to(settings_privacy_path)
|
||||
|
||||
expect(ActivityPub::UpdateDistributionWorker)
|
||||
.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_in)
|
||||
end
|
||||
|
||||
it 'updates the user profile' do
|
||||
put :update, params: { account: { discoverable: '1', settings: { indexable: '1' } } }
|
||||
|
||||
expect(response)
|
||||
.to render_template(:show)
|
||||
|
||||
expect(ActivityPub::UpdateDistributionWorker)
|
||||
.to_not have_received(:perform_in)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def failing_update_service
|
||||
instance_double(UpdateAccountService, call: false)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -32,23 +32,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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue