relationships_controller_spec.rb 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. require 'rails_helper'
  2. describe RelationshipsController do
  3. render_views
  4. let(:user) { Fabricate(:user) }
  5. shared_examples 'authenticate user' do
  6. it 'redirects when not signed in' do
  7. is_expected.to redirect_to '/auth/sign_in'
  8. end
  9. end
  10. describe 'GET #show' do
  11. subject { get :show, params: { page: 2, relationship: 'followed_by' } }
  12. it 'assigns @accounts' do
  13. Fabricate(:account, domain: 'old').follow!(user.account)
  14. Fabricate(:account, domain: 'recent').follow!(user.account)
  15. sign_in user, scope: :user
  16. subject
  17. assigned = assigns(:accounts).per(1).to_a
  18. expect(assigned.size).to eq 1
  19. expect(assigned[0].domain).to eq 'old'
  20. end
  21. it 'returns http success' do
  22. sign_in user, scope: :user
  23. subject
  24. expect(response).to have_http_status(200)
  25. end
  26. include_examples 'authenticate user'
  27. end
  28. describe 'PATCH #update' do
  29. let(:poopfeast) { Fabricate(:account, username: 'poopfeast', domain: 'example.com') }
  30. shared_examples 'redirects back to followers page' do
  31. it 'redirects back to followers page' do
  32. poopfeast.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: [poopfeast.id] }, block_domains: '' } }
  44. it 'soft-blocks followers from selected domains' do
  45. poopfeast.follow!(user.account)
  46. sign_in user, scope: :user
  47. subject
  48. expect(poopfeast.following?(user.account)).to be false
  49. end
  50. include_examples 'authenticate user'
  51. include_examples 'redirects back to followers page'
  52. end
  53. end
  54. end