domain_blocks_controller_spec.rb 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. require 'rails_helper'
  2. RSpec.describe Admin::DomainBlocksController, type: :controller do
  3. render_views
  4. before do
  5. sign_in Fabricate(:user, admin: true), scope: :user
  6. end
  7. describe 'GET #index' do
  8. it 'returns http success' do
  9. get :index
  10. expect(response).to have_http_status(:success)
  11. end
  12. end
  13. describe 'GET #new' do
  14. it 'returns http success' do
  15. get :new
  16. expect(response).to have_http_status(:success)
  17. end
  18. end
  19. describe 'GET #show' do
  20. it 'returns http success' do
  21. domain_block = Fabricate(:domain_block)
  22. get :show, params: { id: domain_block.id }
  23. expect(response).to have_http_status(:success)
  24. end
  25. end
  26. describe 'POST #create' do
  27. it 'blocks the domain' do
  28. allow(DomainBlockWorker).to receive(:perform_async).and_return(true)
  29. post :create, params: { domain_block: { domain: 'example.com', severity: 'silence' } }
  30. expect(DomainBlockWorker).to have_received(:perform_async)
  31. expect(response).to redirect_to(admin_domain_blocks_path)
  32. end
  33. end
  34. describe 'DELETE #destroy' do
  35. it 'unblocks the domain' do
  36. service = double(call: true)
  37. allow(UnblockDomainService).to receive(:new).and_return(service)
  38. domain_block = Fabricate(:domain_block)
  39. delete :destroy, params: { id: domain_block.id, domain_block: { retroactive: '1' } }
  40. expect(service).to have_received(:call).with(domain_block, true)
  41. expect(response).to redirect_to(admin_domain_blocks_path)
  42. end
  43. end
  44. end