email_domain_blocks_controller_spec.rb 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe Admin::EmailDomainBlocksController, type: :controller do
  4. render_views
  5. before do
  6. sign_in Fabricate(:user, admin: true), scope: :user
  7. end
  8. describe 'GET #index' do
  9. around do |example|
  10. default_per_page = EmailDomainBlock.default_per_page
  11. EmailDomainBlock.paginates_per 1
  12. example.run
  13. EmailDomainBlock.paginates_per default_per_page
  14. end
  15. it 'returns http success' do
  16. 2.times { Fabricate(:email_domain_block) }
  17. get :index, params: { page: 2 }
  18. expect(response).to have_http_status(200)
  19. end
  20. end
  21. describe 'GET #new' do
  22. it 'returns http success' do
  23. get :new
  24. expect(response).to have_http_status(200)
  25. end
  26. end
  27. describe 'POST #create' do
  28. context 'when resolve button is pressed' do
  29. before do
  30. post :create, params: { email_domain_block: { domain: 'example.com' } }
  31. end
  32. it 'renders new template' do
  33. expect(response).to render_template(:new)
  34. end
  35. end
  36. context 'when save button is pressed' do
  37. before do
  38. post :create, params: { email_domain_block: { domain: 'example.com' }, save: '' }
  39. end
  40. it 'blocks the domain' do
  41. expect(EmailDomainBlock.find_by(domain: 'example.com')).to_not be_nil
  42. end
  43. it 'redirects to e-mail domain blocks' do
  44. expect(response).to redirect_to(admin_email_domain_blocks_path)
  45. end
  46. end
  47. end
  48. end