account_controller_concern_spec.rb 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. around do |example|
  11. registrations_mode = Setting.registrations_mode
  12. example.run
  13. Setting.registrations_mode = registrations_mode
  14. end
  15. before do
  16. routes.draw { get 'success' => 'anonymous#success' }
  17. end
  18. context 'when account is unconfirmed' do
  19. it 'returns http not found' do
  20. account = Fabricate(:user, confirmed_at: nil).account
  21. get 'success', params: { account_username: account.username }
  22. expect(response).to have_http_status(404)
  23. end
  24. end
  25. context 'when account is not approved' do
  26. it 'returns http not found' do
  27. Setting.registrations_mode = 'approved'
  28. account = Fabricate(:user, approved: false).account
  29. get 'success', params: { account_username: account.username }
  30. expect(response).to have_http_status(404)
  31. end
  32. end
  33. context 'when account is suspended' do
  34. it 'returns http gone' do
  35. account = Fabricate(:account, suspended: true)
  36. get 'success', params: { account_username: account.username }
  37. expect(response).to have_http_status(410)
  38. end
  39. end
  40. context 'when account is deleted by owner' do
  41. it 'returns http gone' do
  42. account = Fabricate(:account, suspended: true, user: nil)
  43. get 'success', params: { account_username: account.username }
  44. expect(response).to have_http_status(410)
  45. end
  46. end
  47. context 'when account is not suspended' do
  48. it 'assigns @account' do
  49. account = Fabricate(:account)
  50. get 'success', params: { account_username: account.username }
  51. expect(assigns(:account)).to eq account
  52. end
  53. it 'sets link headers' do
  54. account = Fabricate(:account, username: 'username')
  55. get 'success', params: { account_username: 'username' }
  56. 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"'
  57. end
  58. it 'returns http success' do
  59. account = Fabricate(:account)
  60. get 'success', params: { account_username: account.username }
  61. expect(response).to have_http_status(200)
  62. end
  63. end
  64. end