You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.6 KiB

  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 'renders email blacks' do
  16. 2.times { Fabricate(:email_domain_block) }
  17. get :index, params: { page: 2 }
  18. assigned = assigns(:email_domain_blocks)
  19. expect(assigned.count).to eq 1
  20. expect(assigned.klass).to be EmailDomainBlock
  21. expect(response).to have_http_status(200)
  22. end
  23. end
  24. describe 'GET #new' do
  25. it 'assigns a new email black' do
  26. get :new
  27. expect(assigns(:email_domain_block)).to be_instance_of(EmailDomainBlock)
  28. expect(response).to have_http_status(200)
  29. end
  30. end
  31. describe 'POST #create' do
  32. it 'blocks the domain when succeeded to save' do
  33. post :create, params: { email_domain_block: { domain: 'example.com' } }
  34. expect(flash[:notice]).to eq I18n.t('admin.email_domain_blocks.created_msg')
  35. expect(response).to redirect_to(admin_email_domain_blocks_path)
  36. end
  37. end
  38. describe 'DELETE #destroy' do
  39. it 'unblocks the domain' do
  40. email_domain_block = Fabricate(:email_domain_block)
  41. delete :destroy, params: { id: email_domain_block.id }
  42. expect(flash[:notice]).to eq I18n.t('admin.email_domain_blocks.destroyed_msg')
  43. expect(response).to redirect_to(admin_email_domain_blocks_path)
  44. end
  45. end
  46. end