domain_allows_controller_spec.rb 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe Admin::DomainAllowsController 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(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 = instance_double(UnallowDomainService, 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