Commit eee454e1 authored by Shinya Maeda's avatar Shinya Maeda Committed by Alessio Caiazza

Fix validation methods in Config::Entry::Job. Added spec for that

parent 6fb1e0d8
...@@ -30,19 +30,14 @@ module Gitlab ...@@ -30,19 +30,14 @@ module Gitlab
validates :when, validates :when,
inclusion: { in: %w[on_success on_failure always manual delayed], inclusion: { in: %w[on_success on_failure always manual delayed],
message: 'should be on_success, on_failure, ' \ message: 'should be on_success, on_failure, ' \
'always or manual' } 'always, manual or delayed' }
validates :dependencies, array_of_strings: true validates :dependencies, array_of_strings: true
validates :extends, type: String validates :extends, type: String
with_options if: :delayed? do
validates :start_in, duration: true, allow_nil: false
end end
with_options unless: :delayed? do validates :start_in, duration: true, if: :delayed?
validates :start_in, presence: false validates :start_in, absence: true, unless: :delayed?
end
end
end end
entry :before_script, Entry::Script, entry :before_script, Entry::Script,
......
...@@ -39,6 +39,16 @@ describe Gitlab::Ci::Config::Entry::Job do ...@@ -39,6 +39,16 @@ describe Gitlab::Ci::Config::Entry::Job do
expect(entry.errors).to include "job name can't be blank" expect(entry.errors).to include "job name can't be blank"
end end
end end
context 'when delayed job' do
context 'when start_in is specified' do
let(:config) { { script: 'echo', when: 'delayed', start_in: '1 day' } }
it 'returns error about invalid type' do
expect(entry).to be_valid
end
end
end
end end
context 'when entry value is not correct' do context 'when entry value is not correct' do
...@@ -129,6 +139,43 @@ describe Gitlab::Ci::Config::Entry::Job do ...@@ -129,6 +139,43 @@ describe Gitlab::Ci::Config::Entry::Job do
end end
end end
end end
context 'when delayed job' do
context 'when start_in is specified' do
let(:config) { { script: 'echo', when: 'delayed', start_in: '1 day' } }
it 'returns error about invalid type' do
expect(entry).to be_valid
end
end
context 'when start_in is empty' do
let(:config) { { when: 'delayed', start_in: nil } }
it 'returns error about invalid type' do
expect(entry).not_to be_valid
expect(entry.errors).to include 'job start in should be a duration'
end
end
context 'when start_in is not formateed ad a duration' do
let(:config) { { when: 'delayed', start_in: 'test' } }
it 'returns error about invalid type' do
expect(entry).not_to be_valid
expect(entry.errors).to include 'job start in should be a duration'
end
end
end
context 'when start_in specified without delayed specification' do
let(:config) { { start_in: '1 day' } }
it 'returns error about invalid type' do
expect(entry).not_to be_valid
expect(entry.errors).to include 'job start in must be blank'
end
end
end end
end end
...@@ -238,6 +285,24 @@ describe Gitlab::Ci::Config::Entry::Job do ...@@ -238,6 +285,24 @@ describe Gitlab::Ci::Config::Entry::Job do
end end
end end
describe '#delayed?' do
context 'when job is a delayed' do
let(:config) { { script: 'deploy', when: 'delayed' } }
it 'is a delayed' do
expect(entry).to be_delayed
end
end
context 'when job is not a delayed' do
let(:config) { { script: 'deploy' } }
it 'is not a delayed' do
expect(entry).not_to be_delayed
end
end
end
describe '#ignored?' do describe '#ignored?' do
context 'when job is a manual action' do context 'when job is a manual action' do
context 'when it is not specified if job is allowed to fail' do context 'when it is not specified if job is allowed to fail' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment