relationships_controller_spec.rb 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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', salmon_url: 'http://example.com/salmon') }
  30. before do
  31. stub_request(:post, 'http://example.com/salmon').to_return(status: 200)
  32. end
  33. shared_examples 'redirects back to followers page' do
  34. it 'redirects back to followers page' do
  35. poopfeast.follow!(user.account)
  36. sign_in user, scope: :user
  37. subject
  38. expect(response).to redirect_to(relationships_path)
  39. end
  40. end
  41. context 'when select parameter is not provided' do
  42. subject { patch :update }
  43. include_examples 'redirects back to followers page'
  44. end
  45. context 'when select parameter is provided' do
  46. subject { patch :update, params: { form_account_batch: { account_ids: [poopfeast.id] }, block_domains: '' } }
  47. it 'soft-blocks followers from selected domains' do
  48. poopfeast.follow!(user.account)
  49. sign_in user, scope: :user
  50. subject
  51. expect(poopfeast.following?(user.account)).to be false
  52. end
  53. include_examples 'authenticate user'
  54. include_examples 'redirects back to followers page'
  55. end
  56. end
  57. end