You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
2.2 KiB

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