about summary refs log tree commit diff
path: root/spec/lib/admin/system_check/rules_check_spec.rb
blob: fb3293fb2d06150b9c3d9980391a67502a4eef51 (plain) (blame)
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
# frozen_string_literal: true

require 'rails_helper'

describe Admin::SystemCheck::RulesCheck do
  subject(:check) { described_class.new(user) }

  let(:user) { Fabricate(:user) }

  describe 'skip?' do
    context 'when user can manage rules' do
      before { allow(user).to receive(:can?).with(:manage_rules).and_return(true) }

      it 'returns false' do
        expect(check.skip?).to be false
      end
    end

    context 'when user cannot manage rules' do
      before { allow(user).to receive(:can?).with(:manage_rules).and_return(false) }

      it 'returns true' do
        expect(check.skip?).to be true
      end
    end
  end

  describe 'pass?' do
    context 'when there is not a kept rule' do
      it 'returns false' do
        expect(check.pass?).to be false
      end
    end

    context 'when there is a kept rule' do
      before { Fabricate(:rule) }

      it 'returns true' do
        expect(check.pass?).to be true
      end
    end
  end

  describe 'message' do
    it 'sends class name symbol to message instance' do
      allow(Admin::SystemCheck::Message).to receive(:new).with(:rules_check, nil, '/admin/rules')

      check.message

      expect(Admin::SystemCheck::Message).to have_received(:new).with(:rules_check, nil, '/admin/rules')
    end
  end
end