pictures_controller_spec.rb 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe Settings::PicturesController do
  4. render_views
  5. let!(:user) { Fabricate(:user) }
  6. before do
  7. sign_in user, scope: :user
  8. end
  9. describe 'DELETE #destroy' do
  10. context 'with invalid picture id' do
  11. it 'returns http bad request' do
  12. delete :destroy, params: { id: 'invalid' }
  13. expect(response).to have_http_status(400)
  14. end
  15. end
  16. context 'with valid picture id' do
  17. context 'when account updates correctly' do
  18. let(:service) { instance_double(UpdateAccountService, call: true) }
  19. before do
  20. allow(UpdateAccountService).to receive(:new).and_return(service)
  21. end
  22. it 'updates the account' do
  23. delete :destroy, params: { id: 'avatar' }
  24. expect(response).to redirect_to(settings_profile_path)
  25. expect(response).to have_http_status(303)
  26. expect(service).to have_received(:call).with(user.account, { 'avatar' => nil, 'avatar_remote_url' => '' })
  27. end
  28. end
  29. context 'when account cannot update' do
  30. let(:service) { instance_double(UpdateAccountService, call: false) }
  31. before do
  32. allow(UpdateAccountService).to receive(:new).and_return(service)
  33. end
  34. it 'redirects to profile' do
  35. delete :destroy, params: { id: 'avatar' }
  36. expect(response).to redirect_to(settings_profile_path)
  37. end
  38. end
  39. end
  40. end
  41. end