Commit d8478d16 authored by Shinya Maeda's avatar Shinya Maeda

Fix spec

parent 5547baa3
...@@ -3,6 +3,7 @@ module Ci ...@@ -3,6 +3,7 @@ module Ci
include TokenAuthenticatable include TokenAuthenticatable
include AfterCommitQueue include AfterCommitQueue
include Presentable include Presentable
include Importable
belongs_to :runner belongs_to :runner
belongs_to :trigger_request belongs_to :trigger_request
...@@ -26,7 +27,7 @@ module Ci ...@@ -26,7 +27,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 validates :protected, inclusion: { in: [true, false], unless: :importing? }, 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) }
......
...@@ -37,7 +37,8 @@ class Spinach::Features::ProjectPages < Spinach::FeatureSteps ...@@ -37,7 +37,8 @@ class Spinach::Features::ProjectPages < Spinach::FeatureSteps
step 'pages are deployed' do step 'pages are deployed' do
pipeline = @project.pipelines.create(ref: 'HEAD', pipeline = @project.pipelines.create(ref: 'HEAD',
sha: @project.commit('HEAD').sha, sha: @project.commit('HEAD').sha,
source: :push) source: :push,
protected: false)
build = build(:ci_build, build = build(:ci_build,
project: @project, project: @project,
......
...@@ -74,7 +74,8 @@ module API ...@@ -74,7 +74,8 @@ module API
source: :external, source: :external,
sha: commit.sha, sha: commit.sha,
ref: ref, ref: ref,
user: current_user) user: current_user,
protected: @project.protected_for?(ref))
end end
status = GenericCommitStatus.running_or_pending.find_or_initialize_by( status = GenericCommitStatus.running_or_pending.find_or_initialize_by(
...@@ -82,7 +83,8 @@ module API ...@@ -82,7 +83,8 @@ module API
pipeline: pipeline, pipeline: pipeline,
name: name, name: name,
ref: ref, ref: ref,
user: current_user user: current_user,
protected: @project.protected_for?(ref)
) )
optional_attributes = optional_attributes =
......
...@@ -16,8 +16,8 @@ describe API::CommitStatuses do ...@@ -16,8 +16,8 @@ describe API::CommitStatuses do
let(:get_url) { "/projects/#{project.id}/repository/commits/#{sha}/statuses" } let(:get_url) { "/projects/#{project.id}/repository/commits/#{sha}/statuses" }
context 'ci commit exists' do context 'ci commit exists' do
let!(:master) { project.pipelines.create(source: :push, sha: commit.id, ref: 'master') } let!(:master) { project.pipelines.create(source: :push, sha: commit.id, ref: 'master', protected: false) }
let!(:develop) { project.pipelines.create(source: :push, sha: commit.id, ref: 'develop') } let!(:develop) { project.pipelines.create(source: :push, sha: commit.id, ref: 'develop', protected: false) }
context "reporter user" do context "reporter user" do
let(:statuses_id) { json_response.map { |status| status['id'] } } let(:statuses_id) { json_response.map { |status| status['id'] } }
......
...@@ -565,7 +565,7 @@ describe API::Commits do ...@@ -565,7 +565,7 @@ describe API::Commits do
end end
context 'when the ref has a pipeline' do context 'when the ref has a pipeline' do
let!(:pipeline) { project.pipelines.create(source: :push, ref: 'master', sha: commit.sha) } let!(:pipeline) { project.pipelines.create(source: :push, ref: 'master', sha: commit.sha, protected: false) }
it 'includes a "created" status' do it 'includes a "created" status' do
get api(route, current_user) get api(route, current_user)
......
...@@ -386,7 +386,7 @@ describe API::V3::Commits do ...@@ -386,7 +386,7 @@ describe API::V3::Commits do
end end
it "returns status for CI" do it "returns status for CI" do
pipeline = project.pipelines.create(source: :push, ref: 'master', sha: project.repository.commit.sha) pipeline = project.pipelines.create(source: :push, ref: 'master', sha: project.repository.commit.sha, protected: false)
pipeline.update(status: 'success') pipeline.update(status: 'success')
get v3_api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}", user) get v3_api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}", user)
...@@ -396,7 +396,7 @@ describe API::V3::Commits do ...@@ -396,7 +396,7 @@ describe API::V3::Commits do
end end
it "returns status for CI when pipeline is created" do it "returns status for CI when pipeline is created" do
project.pipelines.create(source: :push, ref: 'master', sha: project.repository.commit.sha) project.pipelines.create(source: :push, ref: 'master', sha: project.repository.commit.sha, protected: false)
get v3_api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}", user) get v3_api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}", user)
......
...@@ -22,7 +22,7 @@ describe Ci::RetryBuildService do ...@@ -22,7 +22,7 @@ describe Ci::RetryBuildService do
%i[type lock_version target_url base_tags %i[type lock_version target_url base_tags
commit_id deployments erased_by_id last_deployment project_id commit_id deployments erased_by_id last_deployment project_id
runner_id tag_taggings taggings tags trigger_request_id runner_id tag_taggings taggings tags trigger_request_id
user_id auto_canceled_by_id retried protected].freeze user_id auto_canceled_by_id retried].freeze
shared_examples 'build duplication' do shared_examples 'build duplication' do
let(:stage) do let(:stage) do
...@@ -48,7 +48,7 @@ describe Ci::RetryBuildService do ...@@ -48,7 +48,7 @@ describe Ci::RetryBuildService do
describe 'clone accessors' do describe 'clone accessors' do
CLONE_ACCESSORS.each do |attribute| CLONE_ACCESSORS.each do |attribute|
it "clones #{attribute} build attribute" do it "clones #{attribute} build attribute" do
expect(new_build.send(attribute)).to be_present expect(new_build.send(attribute)).not_to be_nil
expect(new_build.send(attribute)).to eq build.send(attribute) expect(new_build.send(attribute)).to eq build.send(attribute)
end end
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