diff options
author | Starfall <us@starfall.systems> | 2022-06-06 13:35:20 -0500 |
---|---|---|
committer | Starfall <us@starfall.systems> | 2022-06-06 13:35:20 -0500 |
commit | 78266a002b4735caaef07098ba66419fd71f47c1 (patch) | |
tree | 4ba2bc330d5ed4b6a3a926ab9a03a89f56bc8843 /spec/controllers/admin/export_domain_blocks_controller_spec.rb | |
parent | e9b2e11520056d0ec822ac0862923d00c6a1289c (diff) | |
parent | 434b08e95b1a440bf9ae563b72600d1590106260 (diff) |
Merge remote-tracking branch 'glitch/main'
Diffstat (limited to 'spec/controllers/admin/export_domain_blocks_controller_spec.rb')
-rw-r--r-- | spec/controllers/admin/export_domain_blocks_controller_spec.rb | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/spec/controllers/admin/export_domain_blocks_controller_spec.rb b/spec/controllers/admin/export_domain_blocks_controller_spec.rb new file mode 100644 index 000000000..0493df859 --- /dev/null +++ b/spec/controllers/admin/export_domain_blocks_controller_spec.rb @@ -0,0 +1,35 @@ +require 'rails_helper' + +RSpec.describe Admin::ExportDomainBlocksController, type: :controller do + render_views + + before do + sign_in Fabricate(:user, admin: true), scope: :user + end + + describe 'GET #export' do + it 'renders instances' do + Fabricate(:domain_block, domain: 'bad.domain', severity: 'silence', public_comment: 'bad') + Fabricate(:domain_block, domain: 'worse.domain', severity: 'suspend', reject_media: true, reject_reports: true, public_comment: 'worse', obfuscate: true) + Fabricate(:domain_block, domain: 'reject.media', severity: 'noop', reject_media: true, public_comment: 'reject media') + Fabricate(:domain_block, domain: 'no.op', severity: 'noop', public_comment: 'noop') + + get :export, params: { format: :csv } + expect(response).to have_http_status(200) + expect(response.body).to eq(IO.read(File.join(file_fixture_path, 'domain_blocks.csv'))) + end + end + + describe 'POST #import' do + it 'blocks imported domains' do + post :import, params: { admin_import: { data: fixture_file_upload('domain_blocks.csv') } } + + expect(assigns(:domain_blocks).map(&:domain)).to match_array ['bad.domain', 'worse.domain', 'reject.media'] + end + end + + it 'displays error on no file selected' do + post :import, params: { admin_import: {} } + expect(flash[:alert]).to eq(I18n.t('admin.export_domain_blocks.no_file')) + end +end |