From 5271131658181bd94eb8a57cc877ef281855e132 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Thu, 8 Feb 2024 05:02:53 -0500 Subject: [PATCH] Extract helper method for repeated form fill in admin/domain_blocks feature spec (#29128) --- spec/features/admin/domain_blocks_spec.rb | 31 +++++++++++++---------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/spec/features/admin/domain_blocks_spec.rb b/spec/features/admin/domain_blocks_spec.rb index 6a1405cdf6..99aa7cf1a7 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