domain_allows_controller_spec.rb 1.4 KB

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