aboutsummaryrefslogtreecommitdiffstats
path: root/spec/models/compliance_check_set_spec.rb
blob: fc32b940bb3320db580720431f9982fd6d10da43 (plain)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
require 'rails_helper'

RSpec.describe ComplianceCheckSet, type: :model do
  it 'should have a valid factory' do
    expect(FactoryGirl.build(:compliance_check_set)).to be_valid
  end

  it { should belong_to :referential }
  it { should belong_to :workbench }
  it { should belong_to :compliance_control_set }
  it { should belong_to :parent }

  it { should have_many :compliance_checks }
  it { should have_many :compliance_check_blocks }

  describe "#update_status" do
    it "updates :status to successful when all resources are OK" do
      check_set = create(:compliance_check_set)
      create_list(
        :compliance_check_resource,
        2,
        compliance_check_set: check_set,
        status: 'OK'
      )

      check_set.update_status

      expect(check_set.status).to eq('successful')
    end

    it "updates :status to failed when one resource is ERROR" do
      check_set = create(:compliance_check_set)
      create(
        :compliance_check_resource,
        compliance_check_set: check_set,
        status: 'ERROR'
      )
      create(
        :compliance_check_resource,
        compliance_check_set: check_set,
        status: 'OK'
      )

      check_set.update_status
      expect(check_set.reload.status).to eq('failed')
    end

    it "updates :status to warning when one resource is WARNING" do
      check_set = create(:compliance_check_set)
      create(
        :compliance_check_resource,
        compliance_check_set: check_set,
        status: 'WARNING'
      )
      create(
        :compliance_check_resource,
        compliance_check_set: check_set,
        status: 'OK'
      )

      check_set.update_status

      expect(check_set.reload.status).to eq('warning')
    end

    it "updates :status to successful when resources are IGNORED" do
      check_set = create(:compliance_check_set)
      create(
        :compliance_check_resource,
        compliance_check_set: check_set,
        status: 'IGNORED'
      )
      create(
        :compliance_check_resource,
        compliance_check_set: check_set,
        status: 'OK'
      )

      check_set.update_status

      expect(check_set.status).to eq('warning')
    end

  end

  describe 'possibility to delete the associated compliance_control_set' do
    let!(:compliance_check_set) { create :compliance_check_set }

    it do
      expect{ compliance_check_set.compliance_control_set.delete }
        .to change{ ComplianceControlSet.count }.by(-1)
    end
  end
end