account_controller_concern_spec.rb 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe ApplicationController, type: :controller do
  4. controller do
  5. include AccountControllerConcern
  6. def success
  7. head 200
  8. end
  9. end
  10. before do
  11. routes.draw { get 'success' => 'anonymous#success' }
  12. end
  13. context 'when account is suspended' do
  14. it 'returns http gone' do
  15. account = Fabricate(:account, suspended: true, user: Fabricate(:user))
  16. get 'success', params: { account_username: account.username }
  17. expect(response).to have_http_status(410)
  18. end
  19. end
  20. context 'when account is deleted by owner' do
  21. it 'returns http gone' do
  22. account = Fabricate(:account, suspended: true, user: nil)
  23. get 'success', params: { account_username: account.username }
  24. expect(response).to have_http_status(410)
  25. end
  26. end
  27. context 'when account is not suspended' do
  28. it 'assigns @account' do
  29. account = Fabricate(:account, user: Fabricate(:user))
  30. get 'success', params: { account_username: account.username }
  31. expect(assigns(:account)).to eq account
  32. end
  33. it 'sets link headers' do
  34. account = Fabricate(:account, username: 'username', user: Fabricate(:user))
  35. get 'success', params: { account_username: 'username' }
  36. expect(response.headers['Link'].to_s).to eq '<http://test.host/.well-known/webfinger?resource=acct%3Ausername%40cb6e6126.ngrok.io>; rel="lrdd"; type="application/jrd+json", <https://cb6e6126.ngrok.io/users/username>; rel="alternate"; type="application/activity+json"'
  37. end
  38. it 'returns http success' do
  39. account = Fabricate(:account, user: Fabricate(:user))
  40. get 'success', params: { account_username: account.username }
  41. expect(response).to have_http_status(200)
  42. end
  43. end
  44. end