2017-10-04 15:16:10 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
2023-05-04 05:49:53 +02:00
|
|
|
RSpec.describe Admin::EmailDomainBlocksController do
|
2017-10-04 15:16:10 +02:00
|
|
|
render_views
|
|
|
|
|
|
|
|
before do
|
2022-07-05 02:41:40 +02:00
|
|
|
sign_in Fabricate(:user, role: UserRole.find_by(name: 'Admin')), scope: :user
|
2017-10-04 15:16:10 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #index' do
|
|
|
|
around do |example|
|
|
|
|
default_per_page = EmailDomainBlock.default_per_page
|
2024-01-04 10:07:05 +01:00
|
|
|
EmailDomainBlock.paginates_per 2
|
2017-10-04 15:16:10 +02:00
|
|
|
example.run
|
|
|
|
EmailDomainBlock.paginates_per default_per_page
|
|
|
|
end
|
|
|
|
|
2022-02-24 17:28:23 +01:00
|
|
|
it 'returns http success' do
|
2017-10-04 15:16:10 +02:00
|
|
|
2.times { Fabricate(:email_domain_block) }
|
2024-01-04 10:07:05 +01:00
|
|
|
Fabricate(:email_domain_block, allow_with_approval: true)
|
2017-10-04 15:16:10 +02:00
|
|
|
get :index, params: { page: 2 }
|
2018-04-21 21:35:07 +02:00
|
|
|
expect(response).to have_http_status(200)
|
2017-10-04 15:16:10 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #new' do
|
2022-02-24 17:28:23 +01:00
|
|
|
it 'returns http success' do
|
2017-10-04 15:16:10 +02:00
|
|
|
get :new
|
2018-04-21 21:35:07 +02:00
|
|
|
expect(response).to have_http_status(200)
|
2017-10-04 15:16:10 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'POST #create' do
|
2022-02-24 17:28:23 +01:00
|
|
|
context 'when resolve button is pressed' do
|
|
|
|
before do
|
|
|
|
post :create, params: { email_domain_block: { domain: 'example.com' } }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders new template' do
|
|
|
|
expect(response).to render_template(:new)
|
|
|
|
end
|
2017-10-04 15:16:10 +02:00
|
|
|
end
|
|
|
|
|
2022-02-24 17:28:23 +01:00
|
|
|
context 'when save button is pressed' do
|
|
|
|
before do
|
|
|
|
post :create, params: { email_domain_block: { domain: 'example.com' }, save: '' }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'blocks the domain' do
|
|
|
|
expect(EmailDomainBlock.find_by(domain: 'example.com')).to_not be_nil
|
|
|
|
end
|
2017-10-04 15:16:10 +02:00
|
|
|
|
2022-02-24 17:28:23 +01:00
|
|
|
it 'redirects to e-mail domain blocks' do
|
|
|
|
expect(response).to redirect_to(admin_email_domain_blocks_path)
|
|
|
|
end
|
2017-10-04 15:16:10 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|