profiles_controller_spec.rb 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe Settings::ProfilesController 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' do
  15. expect(response).to have_http_status(200)
  16. end
  17. it 'returns private cache control headers' do
  18. expect(response.headers['Cache-Control']).to include('private, no-store')
  19. end
  20. end
  21. describe 'PUT #update' do
  22. before do
  23. user.account.update(display_name: 'Old name')
  24. end
  25. it 'updates the user profile' do
  26. allow(ActivityPub::UpdateDistributionWorker).to receive(:perform_async)
  27. put :update, params: { account: { display_name: 'New name' } }
  28. expect(account.reload.display_name).to eq 'New name'
  29. expect(response).to redirect_to(settings_profile_path)
  30. expect(ActivityPub::UpdateDistributionWorker).to have_received(:perform_async).with(account.id)
  31. end
  32. end
  33. describe 'PUT #update with new profile image' do
  34. it 'updates profile image' do
  35. allow(ActivityPub::UpdateDistributionWorker).to receive(:perform_async)
  36. expect(account.avatar.instance.avatar_file_name).to be_nil
  37. put :update, params: { account: { avatar: fixture_file_upload('avatar.gif', 'image/gif') } }
  38. expect(response).to redirect_to(settings_profile_path)
  39. expect(account.reload.avatar.instance.avatar_file_name).to_not be_nil
  40. expect(ActivityPub::UpdateDistributionWorker).to have_received(:perform_async).with(account.id)
  41. end
  42. end
  43. end