profiles_controller_spec.rb 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. require 'rails_helper'
  2. RSpec.describe Settings::ProfilesController, type: :controller do
  3. render_views
  4. let!(:user) { Fabricate(:user) }
  5. let(:account) { user.account }
  6. before do
  7. sign_in user, scope: :user
  8. end
  9. describe "GET #show" do
  10. it "returns http success" do
  11. get :show
  12. expect(response).to have_http_status(200)
  13. end
  14. end
  15. describe 'PUT #update' do
  16. before do
  17. user.account.update(display_name: 'Old name')
  18. end
  19. it 'updates the user profile' do
  20. allow(ActivityPub::UpdateDistributionWorker).to receive(:perform_async)
  21. put :update, params: { account: { display_name: 'New name' } }
  22. expect(account.reload.display_name).to eq 'New name'
  23. expect(response).to redirect_to(settings_profile_path)
  24. expect(ActivityPub::UpdateDistributionWorker).to have_received(:perform_async).with(account.id)
  25. end
  26. end
  27. describe 'PUT #update with new profile image' do
  28. it 'updates profile image' do
  29. allow(ActivityPub::UpdateDistributionWorker).to receive(:perform_async)
  30. expect(account.avatar.instance.avatar_file_name).to be_nil
  31. put :update, params: { account: { avatar: fixture_file_upload('avatar.gif', 'image/gif') } }
  32. expect(response).to redirect_to(settings_profile_path)
  33. expect(account.reload.avatar.instance.avatar_file_name).not_to be_nil
  34. expect(ActivityPub::UpdateDistributionWorker).to have_received(:perform_async).with(account.id)
  35. end
  36. end
  37. describe 'PUT #update with oversized image' do
  38. it 'gives the user an error message' do
  39. allow(ActivityPub::UpdateDistributionWorker).to receive(:perform_async)
  40. put :update, params: { account: { avatar: fixture_file_upload('4096x4097.png', 'image/png') } }
  41. expect(response.body).to include('images are not supported')
  42. end
  43. end
  44. end