~cytrogen/masto-fe

ref: 3a679844e499df026be7d5b3a9e80e5bf3ad585a masto-fe/spec/controllers/admin/email_domain_blocks_controller_spec.rb -rw-r--r-- 1.5 KiB
3a679844 — Eugen Rochko Fix `account_id`, `max_id` and `min_id` params not working in search (#26847) 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe Admin::EmailDomainBlocksController do
  render_views

  before do
    sign_in Fabricate(:user, role: UserRole.find_by(name: 'Admin')), scope: :user
  end

  describe 'GET #index' do
    around do |example|
      default_per_page = EmailDomainBlock.default_per_page
      EmailDomainBlock.paginates_per 1
      example.run
      EmailDomainBlock.paginates_per default_per_page
    end

    it 'returns http success' do
      2.times { Fabricate(:email_domain_block) }
      get :index, params: { page: 2 }
      expect(response).to have_http_status(200)
    end
  end

  describe 'GET #new' do
    it 'returns http success' do
      get :new
      expect(response).to have_http_status(200)
    end
  end

  describe 'POST #create' do
    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
    end

    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

      it 'redirects to e-mail domain blocks' do
        expect(response).to redirect_to(admin_email_domain_blocks_path)
      end
    end
  end
end