export_domain_allows_controller_spec.rb 1.4 KB

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