diff --git a/spec/features/admin/domain_blocks_spec.rb b/spec/features/admin/domain_blocks_spec.rb index 6a1405cdf..99aa7cf1a 100644 --- a/spec/features/admin/domain_blocks_spec.rb +++ b/spec/features/admin/domain_blocks_spec.rb @@ -12,9 +12,7 @@ describe 'blocking domains through the moderation interface' do it 'adds a new domain block' do visit new_admin_domain_block_path - fill_in 'domain_block_domain', with: 'example.com' - select I18n.t('admin.domain_blocks.new.severity.silence'), from: 'domain_block_severity' - click_on I18n.t('admin.domain_blocks.new.create') + submit_domain_block('example.com', 'silence') expect(DomainBlock.exists?(domain: 'example.com', severity: 'silence')).to be true expect(DomainBlockWorker).to have_received(:perform_async) @@ -25,9 +23,7 @@ describe 'blocking domains through the moderation interface' do it 'presents a confirmation screen before suspending the domain' do visit new_admin_domain_block_path - fill_in 'domain_block_domain', with: 'example.com' - select I18n.t('admin.domain_blocks.new.severity.suspend'), from: 'domain_block_severity' - click_on I18n.t('admin.domain_blocks.new.create') + submit_domain_block('example.com', 'suspend') # It doesn't immediately block but presents a confirmation screen expect(page).to have_title(I18n.t('admin.domain_blocks.confirm_suspension.title', domain: 'example.com')) @@ -47,9 +43,7 @@ describe 'blocking domains through the moderation interface' do visit new_admin_domain_block_path - fill_in 'domain_block_domain', with: 'example.com' - select I18n.t('admin.domain_blocks.new.severity.suspend'), from: 'domain_block_severity' - click_on I18n.t('admin.domain_blocks.new.create') + submit_domain_block('example.com', 'suspend') # It doesn't immediately block but presents a confirmation screen expect(page).to have_title(I18n.t('admin.domain_blocks.confirm_suspension.title', domain: 'example.com')) @@ -69,9 +63,7 @@ describe 'blocking domains through the moderation interface' do visit new_admin_domain_block_path - fill_in 'domain_block_domain', with: 'subdomain.example.com' - select I18n.t('admin.domain_blocks.new.severity.suspend'), from: 'domain_block_severity' - click_on I18n.t('admin.domain_blocks.new.create') + submit_domain_block('subdomain.example.com', 'suspend') # It doesn't immediately block but presents a confirmation screen expect(page).to have_title(I18n.t('admin.domain_blocks.confirm_suspension.title', domain: 'subdomain.example.com')) @@ -84,8 +76,11 @@ describe 'blocking domains through the moderation interface' do expect(DomainBlockWorker).to have_received(:perform_async) # And leaves the previous block alone - expect(domain_block.reload.severity).to eq 'silence' - expect(domain_block.reload.domain).to eq 'example.com' + expect(domain_block.reload) + .to have_attributes( + severity: eq('silence'), + domain: eq('example.com') + ) end end @@ -109,4 +104,12 @@ describe 'blocking domains through the moderation interface' do expect(domain_block.reload.severity).to eq 'suspend' end end + + private + + def submit_domain_block(domain, severity) + fill_in 'domain_block_domain', with: domain + select I18n.t("admin.domain_blocks.new.severity.#{severity}"), from: 'domain_block_severity' + click_on I18n.t('admin.domain_blocks.new.create') + end end