1
0

relationships_controller_spec.rb 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe RelationshipsController do
  4. render_views
  5. let(:user) { Fabricate(:user) }
  6. describe 'GET #show' do
  7. context 'when signed in' do
  8. before do
  9. sign_in user, scope: :user
  10. get :show, params: { page: 2, relationship: 'followed_by' }
  11. end
  12. it 'returns http success' do
  13. expect(response).to have_http_status(200)
  14. end
  15. it 'returns private cache control headers' do
  16. expect(response.headers['Cache-Control']).to include('private, no-store')
  17. end
  18. end
  19. context 'when not signed in' do
  20. before do
  21. get :show, params: { page: 2, relationship: 'followed_by' }
  22. end
  23. it 'redirects when not signed in' do
  24. expect(response).to redirect_to '/auth/sign_in'
  25. end
  26. end
  27. end
  28. describe 'PATCH #update' do
  29. let(:alice) { Fabricate(:account, username: 'alice', domain: 'example.com') }
  30. shared_examples 'redirects back to followers page' do
  31. it 'redirects back to followers page' do
  32. alice.follow!(user.account)
  33. sign_in user, scope: :user
  34. subject
  35. expect(response).to redirect_to(relationships_path)
  36. end
  37. end
  38. context 'when select parameter is not provided' do
  39. subject { patch :update }
  40. include_examples 'redirects back to followers page'
  41. end
  42. context 'when select parameter is provided' do
  43. subject { patch :update, params: { form_account_batch: { account_ids: [alice.id] }, remove_domains_from_followers: '' } }
  44. it 'soft-blocks followers from selected domains' do
  45. alice.follow!(user.account)
  46. sign_in user, scope: :user
  47. subject
  48. expect(alice.following?(user.account)).to be false
  49. end
  50. it 'does not unfollow users from selected domains' do
  51. user.account.follow!(alice)
  52. sign_in user, scope: :user
  53. subject
  54. expect(user.account.following?(alice)).to be true
  55. end
  56. context 'when not signed in' do
  57. before do
  58. subject
  59. end
  60. it 'redirects when not signed in' do
  61. expect(response).to redirect_to '/auth/sign_in'
  62. end
  63. end
  64. include_examples 'redirects back to followers page'
  65. end
  66. end
  67. end