domain_blocks_spec.rb 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe 'blocking domains through the moderation interface' do
  4. before do
  5. sign_in Fabricate(:user, role: UserRole.find_by(name: 'Admin')), scope: :user
  6. end
  7. context 'when silencing a new domain' do
  8. it 'adds a new domain block' do
  9. visit new_admin_domain_block_path
  10. fill_in 'domain_block_domain', with: 'example.com'
  11. select I18n.t('admin.domain_blocks.new.severity.silence'), from: 'domain_block_severity'
  12. click_on I18n.t('admin.domain_blocks.new.create')
  13. expect(DomainBlock.exists?(domain: 'example.com', severity: 'silence')).to be true
  14. end
  15. end
  16. context 'when suspending a new domain' do
  17. it 'presents a confirmation screen before suspending the domain' do
  18. visit new_admin_domain_block_path
  19. fill_in 'domain_block_domain', with: 'example.com'
  20. select I18n.t('admin.domain_blocks.new.severity.suspend'), from: 'domain_block_severity'
  21. click_on I18n.t('admin.domain_blocks.new.create')
  22. # It presents a confirmation screen
  23. expect(page).to have_title(I18n.t('admin.domain_blocks.confirm_suspension.title', domain: 'example.com'))
  24. # Confirming creates a block
  25. click_on I18n.t('admin.domain_blocks.confirm_suspension.confirm')
  26. expect(DomainBlock.exists?(domain: 'example.com', severity: 'suspend')).to be true
  27. end
  28. end
  29. context 'when suspending a domain that is already silenced' do
  30. it 'presents a confirmation screen before suspending the domain' do
  31. domain_block = Fabricate(:domain_block, domain: 'example.com', severity: 'silence')
  32. visit new_admin_domain_block_path
  33. fill_in 'domain_block_domain', with: 'example.com'
  34. select I18n.t('admin.domain_blocks.new.severity.suspend'), from: 'domain_block_severity'
  35. click_on I18n.t('admin.domain_blocks.new.create')
  36. # It presents a confirmation screen
  37. expect(page).to have_title(I18n.t('admin.domain_blocks.confirm_suspension.title', domain: 'example.com'))
  38. # Confirming updates the block
  39. click_on I18n.t('admin.domain_blocks.confirm_suspension.confirm')
  40. expect(domain_block.reload.severity).to eq 'suspend'
  41. end
  42. end
  43. context 'when suspending a subdomain of an already-silenced domain' do
  44. it 'presents a confirmation screen before suspending the domain' do
  45. domain_block = Fabricate(:domain_block, domain: 'example.com', severity: 'silence')
  46. visit new_admin_domain_block_path
  47. fill_in 'domain_block_domain', with: 'subdomain.example.com'
  48. select I18n.t('admin.domain_blocks.new.severity.suspend'), from: 'domain_block_severity'
  49. click_on I18n.t('admin.domain_blocks.new.create')
  50. # It presents a confirmation screen
  51. expect(page).to have_title(I18n.t('admin.domain_blocks.confirm_suspension.title', domain: 'subdomain.example.com'))
  52. # Confirming creates the block
  53. click_on I18n.t('admin.domain_blocks.confirm_suspension.confirm')
  54. expect(DomainBlock.where(domain: 'subdomain.example.com', severity: 'suspend')).to exist
  55. # And leaves the previous block alone
  56. expect(domain_block.reload.severity).to eq 'silence'
  57. expect(domain_block.reload.domain).to eq 'example.com'
  58. end
  59. end
  60. context 'when editing a domain block' do
  61. it 'presents a confirmation screen before suspending the domain' do
  62. domain_block = Fabricate(:domain_block, domain: 'example.com', severity: 'silence')
  63. visit edit_admin_domain_block_path(domain_block)
  64. select I18n.t('admin.domain_blocks.new.severity.suspend'), from: 'domain_block_severity'
  65. click_on I18n.t('generic.save_changes')
  66. # It presents a confirmation screen
  67. expect(page).to have_title(I18n.t('admin.domain_blocks.confirm_suspension.title', domain: 'example.com'))
  68. # Confirming updates the block
  69. click_on I18n.t('admin.domain_blocks.confirm_suspension.confirm')
  70. expect(domain_block.reload.severity).to eq 'suspend'
  71. end
  72. end
  73. end