aboutsummaryrefslogtreecommitdiffstats
path: root/spec/models/compliance_check_spec.rb
blob: ffa59245c5d63d9adab1365fa200d85683f8abd7 (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
RSpec.describe ComplianceCheck, type: :model do

  it 'should have a valid factory' do
    expect(FactoryGirl.build(:compliance_check)).to be_valid
  end

  it 'has STI disabled' do
    expect( described_class.inheritance_column ).to be_blank
  end

  it { should belong_to :compliance_check_set }
  it { should belong_to :compliance_check_block }

  it { should validate_presence_of :criticity }
  it { should validate_presence_of :name }
  it { should validate_presence_of :code }
  it { should validate_presence_of :origin_code }

  describe ".abort_old" do
    it "changes check sets older than 4 hours to aborted" do
      Timecop.freeze(Time.now) do
        old_check_set = create(
          :compliance_check_set,
          status: 'pending',
          created_at: 4.hours.ago - 1.minute
        )
        current_check_set = create(:compliance_check_set, status: 'pending')

        ComplianceCheckSet.abort_old

        expect(current_check_set.reload.status).to eq('pending')
        expect(old_check_set.reload.status).to eq('aborted')
      end
    end

    it "doesn't work on check sets with a `finished_status`" do
      Timecop.freeze(Time.now) do
        check_set = create(
          :compliance_check_set,
          status: 'successful',
          created_at: 4.hours.ago - 1.minute
        )

        ComplianceCheckSet.abort_old

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