Commit ce7c0ac3 authored by Shinya Maeda's avatar Shinya Maeda

Add validation for protected attributes

parent f3d3cecf
...@@ -26,6 +26,7 @@ module Ci ...@@ -26,6 +26,7 @@ module Ci
validates :coverage, numericality: true, allow_blank: true validates :coverage, numericality: true, allow_blank: true
validates :ref, presence: true validates :ref, presence: true
validates :protected, inclusion: { in: [ true, false ] }, on: :create
scope :unstarted, ->() { where(runner_id: nil) } scope :unstarted, ->() { where(runner_id: nil) }
scope :ignore_failures, ->() { where(allow_failure: false) } scope :ignore_failures, ->() { where(allow_failure: false) }
......
...@@ -36,6 +36,7 @@ module Ci ...@@ -36,6 +36,7 @@ module Ci
validates :sha, presence: { unless: :importing? } validates :sha, presence: { unless: :importing? }
validates :ref, presence: { unless: :importing? } validates :ref, presence: { unless: :importing? }
validates :status, presence: { unless: :importing? } validates :status, presence: { unless: :importing? }
validates :protected, inclusion: { in: [ true, false ], unless: :importing? }, on: :create
validate :valid_commit_sha, unless: :importing? validate :valid_commit_sha, unless: :importing?
after_create :keep_around_commits, unless: :importing? after_create :keep_around_commits, unless: :importing?
......
...@@ -3,7 +3,7 @@ module Ci ...@@ -3,7 +3,7 @@ module Ci
CLONE_ACCESSORS = %i[pipeline project ref tag options commands name CLONE_ACCESSORS = %i[pipeline project ref tag options commands name
allow_failure stage_id stage stage_idx trigger_request allow_failure stage_id stage stage_idx trigger_request
yaml_variables when environment coverage_regex yaml_variables when environment coverage_regex
description tag_list].freeze description tag_list protected].freeze
def execute(build) def execute(build)
reprocess!(build).tap do |new_build| reprocess!(build).tap do |new_build|
......
...@@ -12,6 +12,7 @@ FactoryGirl.define do ...@@ -12,6 +12,7 @@ FactoryGirl.define do
started_at 'Di 29. Okt 09:51:28 CET 2013' started_at 'Di 29. Okt 09:51:28 CET 2013'
finished_at 'Di 29. Okt 09:53:28 CET 2013' finished_at 'Di 29. Okt 09:53:28 CET 2013'
commands 'ls -a' commands 'ls -a'
protected false
options do options do
{ {
...@@ -227,11 +228,11 @@ FactoryGirl.define do ...@@ -227,11 +228,11 @@ FactoryGirl.define do
self.when 'manual' self.when 'manual'
end end
trait(:protected) do trait :protected do
protected true protected true
end end
trait(:unprotected) do trait :unprotected do
protected false protected false
end end
end end
......
...@@ -4,6 +4,7 @@ FactoryGirl.define do ...@@ -4,6 +4,7 @@ FactoryGirl.define do
ref 'master' ref 'master'
sha '97de212e80737a608d939f648d959671fb0a0142' sha '97de212e80737a608d939f648d959671fb0a0142'
status 'pending' status 'pending'
protected false
project project
...@@ -59,6 +60,14 @@ FactoryGirl.define do ...@@ -59,6 +60,14 @@ FactoryGirl.define do
trait :failed do trait :failed do
status :failed status :failed
end end
trait :protected do
protected true
end
trait :unprotected do
protected false
end
end end
end end
end end
...@@ -59,7 +59,11 @@ describe Ci::Build do ...@@ -59,7 +59,11 @@ describe Ci::Build do
end end
context 'when protected is false' do context 'when protected is false' do
let!(:job) { create(:ci_build, protected: nil) } let!(:job) { create(:ci_build) }
before do
job.update_attribute(:protected, nil)
end
it { is_expected.not_to include(job) } it { is_expected.not_to include(job) }
end end
......
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