domain_allows_controller_spec.rb 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe Admin::DomainAllowsController, type: :controller 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 #new' do
  9. it 'assigns a new domain allow' do
  10. get :new
  11. expect(assigns(:domain_allow)).to be_instance_of(DomainAllow)
  12. expect(response).to have_http_status(200)
  13. end
  14. end
  15. describe 'POST #create' do
  16. it 'blocks the domain when succeeded to save' do
  17. post :create, params: { domain_allow: { domain: 'example.com' } }
  18. expect(flash[:notice]).to eq I18n.t('admin.domain_allows.created_msg')
  19. expect(response).to redirect_to(admin_instances_path)
  20. end
  21. it 'renders new when failed to save' do
  22. Fabricate(:domain_allow, domain: 'example.com')
  23. post :create, params: { domain_allow: { domain: 'example.com' } }
  24. expect(response).to render_template :new
  25. end
  26. end
  27. describe 'DELETE #destroy' do
  28. it 'disallows the domain' do
  29. service = double(call: true)
  30. allow(UnallowDomainService).to receive(:new).and_return(service)
  31. domain_allow = Fabricate(:domain_allow)
  32. delete :destroy, params: { id: domain_allow.id }
  33. expect(service).to have_received(:call).with(domain_allow)
  34. expect(flash[:notice]).to eq I18n.t('admin.domain_allows.destroyed_msg')
  35. expect(response).to redirect_to(admin_instances_path)
  36. end
  37. end
  38. end