privacy_controller_spec.rb 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe Settings::PrivacyController do
  4. render_views
  5. let!(:user) { Fabricate(:user) }
  6. let(:account) { user.account }
  7. before do
  8. sign_in user, scope: :user
  9. end
  10. describe 'GET #show' do
  11. before do
  12. get :show
  13. end
  14. it 'returns http success with private cache control headers', :aggregate_failures do
  15. expect(response)
  16. .to have_http_status(200)
  17. .and have_attributes(
  18. headers: include(
  19. 'Cache-Control' => 'private, no-store'
  20. )
  21. )
  22. end
  23. end
  24. describe 'PUT #update' do
  25. context 'when update succeeds' do
  26. before do
  27. allow(ActivityPub::UpdateDistributionWorker).to receive(:perform_async)
  28. end
  29. it 'updates the user profile' do
  30. put :update, params: { account: { discoverable: '1', settings: { indexable: '1' } } }
  31. expect(account.reload.discoverable)
  32. .to be(true)
  33. expect(response)
  34. .to redirect_to(settings_privacy_path)
  35. expect(ActivityPub::UpdateDistributionWorker)
  36. .to have_received(:perform_async).with(account.id)
  37. end
  38. end
  39. context 'when update fails' do
  40. before do
  41. allow(UpdateAccountService).to receive(:new).and_return(failing_update_service)
  42. allow(ActivityPub::UpdateDistributionWorker).to receive(:perform_async)
  43. end
  44. it 'updates the user profile' do
  45. put :update, params: { account: { discoverable: '1', settings: { indexable: '1' } } }
  46. expect(response)
  47. .to render_template(:show)
  48. expect(ActivityPub::UpdateDistributionWorker)
  49. .to_not have_received(:perform_async)
  50. end
  51. private
  52. def failing_update_service
  53. instance_double(UpdateAccountService, call: false)
  54. end
  55. end
  56. end
  57. end