Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cron_validator_spec.rb « validators « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bd7fe2429571d0ecab159542fcc206c77c0190a7 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe CronValidator do
  subject do
    Class.new do
      include ActiveModel::Model
      include ActiveModel::Validations
      attr_accessor :cron

      validates :cron, cron: true

      def cron_timezone
        'UTC'
      end
    end.new
  end

  it 'validates valid crontab' do
    subject.cron = '0 23 * * 5'

    expect(subject.valid?).to be_truthy
  end

  it 'validates invalid crontab' do
    subject.cron = 'not a cron'

    expect(subject.valid?).to be_falsy
  end

  context 'cron field is not whitelisted' do
    subject do
      Class.new do
        include ActiveModel::Model
        include ActiveModel::Validations
        attr_accessor :cron_partytime

        validates :cron_partytime, cron: true
      end.new
    end

    it 'raises an error' do
      subject.cron_partytime = '0 23 * * 5'

      expect { subject.valid? }.to raise_error(StandardError, "Non-whitelisted attribute")
    end
  end
end