profiles_controller_spec.rb 1.9 KB

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