export_domain_allows_controller_spec.rb 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe Admin::ExportDomainAllowsController do
  4. render_views
  5. before do
  6. sign_in Fabricate(:user, role: UserRole.find_by(name: 'Admin')), scope: :user
  7. end
  8. describe 'GET #export' do
  9. it 'renders instances' do
  10. Fabricate(:domain_allow, domain: 'good.domain')
  11. Fabricate(:domain_allow, domain: 'better.domain')
  12. get :export, params: { format: :csv }
  13. expect(response).to have_http_status(200)
  14. expect(response.body).to eq(File.read(File.join(file_fixture_path, 'domain_allows.csv')))
  15. end
  16. end
  17. describe 'POST #import' do
  18. it 'allows imported domains' do
  19. post :import, params: { admin_import: { data: fixture_file_upload('domain_allows.csv') } }
  20. expect(response).to redirect_to(admin_instances_path)
  21. # Header should not be imported
  22. expect(DomainAllow.where(domain: '#domain').present?).to be(false)
  23. # Domains should now be added
  24. get :export, params: { format: :csv }
  25. expect(response).to have_http_status(200)
  26. expect(response.body).to eq(File.read(File.join(file_fixture_path, 'domain_allows.csv')))
  27. end
  28. it 'displays error on no file selected' do
  29. post :import, params: { admin_import: {} }
  30. expect(response).to redirect_to(admin_instances_path)
  31. expect(flash[:error]).to eq(I18n.t('admin.export_domain_allows.no_file'))
  32. end
  33. end
  34. end