logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

follower_domains_controller_spec.rb (2419B)


  1. require 'rails_helper'
  2. describe Settings::FollowerDomainsController 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 } }
  12. it 'assigns @account' do
  13. sign_in user, scope: :user
  14. subject
  15. expect(assigns(:account)).to eq user.account
  16. end
  17. it 'assigns @domains' do
  18. Fabricate(:account, domain: 'old').follow!(user.account)
  19. Fabricate(:account, domain: 'recent').follow!(user.account)
  20. sign_in user, scope: :user
  21. subject
  22. assigned = assigns(:domains).per(1).to_a
  23. expect(assigned.size).to eq 1
  24. expect(assigned[0].accounts_from_domain).to eq 1
  25. expect(assigned[0].domain).to eq 'old'
  26. end
  27. it 'returns http success' do
  28. sign_in user, scope: :user
  29. subject
  30. expect(response).to have_http_status(:success)
  31. end
  32. include_examples 'authenticate user'
  33. end
  34. describe 'PATCH #update' do
  35. let(:poopfeast) { Fabricate(:account, username: 'poopfeast', domain: 'example.com', salmon_url: 'http://example.com/salmon') }
  36. before do
  37. stub_request(:post, 'http://example.com/salmon').to_return(status: 200)
  38. end
  39. shared_examples 'redirects back to followers page' do |notice|
  40. it 'redirects back to followers page' do
  41. poopfeast.follow!(user.account)
  42. sign_in user, scope: :user
  43. subject
  44. expect(flash[:notice]).to eq notice
  45. expect(response).to redirect_to(settings_follower_domains_path)
  46. end
  47. end
  48. context 'when select parameter is not provided' do
  49. subject { patch :update }
  50. include_examples 'redirects back to followers page', 'In the process of soft-blocking followers from 0 domains...'
  51. end
  52. context 'when select parameter is provided' do
  53. subject { patch :update, params: { select: ['example.com'] } }
  54. it 'soft-blocks followers from selected domains' do
  55. poopfeast.follow!(user.account)
  56. sign_in user, scope: :user
  57. subject
  58. expect(poopfeast.following?(user.account)).to be false
  59. end
  60. include_examples 'authenticate user'
  61. include_examples 'redirects back to followers page', 'In the process of soft-blocking followers from one domain...'
  62. end
  63. end
  64. end