闭社主体 forked from https://github.com/tootsuite/mastodon
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.

73 lines
2.5 KiB

  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 #new' do
  8. it 'assigns a new domain block' do
  9. get :new
  10. expect(assigns(:domain_block)).to be_instance_of(DomainBlock)
  11. expect(response).to have_http_status(200)
  12. end
  13. end
  14. describe 'GET #show' do
  15. it 'returns http success' do
  16. domain_block = Fabricate(:domain_block)
  17. get :show, params: { id: domain_block.id }
  18. expect(response).to have_http_status(200)
  19. end
  20. end
  21. describe 'POST #create' do
  22. it 'blocks the domain when succeeded to save' do
  23. allow(DomainBlockWorker).to receive(:perform_async).and_return(true)
  24. post :create, params: { domain_block: { domain: 'example.com', severity: 'silence' } }
  25. expect(DomainBlockWorker).to have_received(:perform_async)
  26. expect(flash[:notice]).to eq I18n.t('admin.domain_blocks.created_msg')
  27. expect(response).to redirect_to(admin_instances_path(limited: '1'))
  28. end
  29. it 'renders new when failed to save' do
  30. Fabricate(:domain_block, domain: 'example.com', severity: 'suspend')
  31. allow(DomainBlockWorker).to receive(:perform_async).and_return(true)
  32. post :create, params: { domain_block: { domain: 'example.com', severity: 'silence' } }
  33. expect(DomainBlockWorker).not_to have_received(:perform_async)
  34. expect(response).to render_template :new
  35. end
  36. it 'allows upgrading a block' do
  37. Fabricate(:domain_block, domain: 'example.com', severity: 'silence')
  38. allow(DomainBlockWorker).to receive(:perform_async).and_return(true)
  39. post :create, params: { domain_block: { domain: 'example.com', severity: 'silence', reject_media: true, reject_reports: true } }
  40. expect(DomainBlockWorker).to have_received(:perform_async)
  41. expect(flash[:notice]).to eq I18n.t('admin.domain_blocks.created_msg')
  42. expect(response).to redirect_to(admin_instances_path(limited: '1'))
  43. end
  44. end
  45. describe 'DELETE #destroy' do
  46. it 'unblocks the domain' do
  47. service = double(call: true)
  48. allow(UnblockDomainService).to receive(:new).and_return(service)
  49. domain_block = Fabricate(:domain_block)
  50. delete :destroy, params: { id: domain_block.id }
  51. expect(service).to have_received(:call).with(domain_block)
  52. expect(flash[:notice]).to eq I18n.t('admin.domain_blocks.destroyed_msg')
  53. expect(response).to redirect_to(admin_instances_path(limited: '1'))
  54. end
  55. end
  56. end