Commit 718ece6d authored by Grzegorz Bizon's avatar Grzegorz Bizon

Fix build specs after using `set` instead of `let`

parent 2f6802cd
...@@ -2,7 +2,8 @@ require 'spec_helper' ...@@ -2,7 +2,8 @@ require 'spec_helper'
describe Ci::Build do describe Ci::Build do
set(:user) { create(:user) } set(:user) { create(:user) }
set(:project) { create(:project, :repository) } set(:group) { create(:group, :access_requestable) }
set(:project) { create(:project, :repository, group: group) }
set(:pipeline) do set(:pipeline) do
create(:ci_pipeline, project: project, create(:ci_pipeline, project: project,
...@@ -1196,6 +1197,8 @@ describe Ci::Build do ...@@ -1196,6 +1197,8 @@ describe Ci::Build do
end end
context 'use from gitlab-ci.yml' do context 'use from gitlab-ci.yml' do
let(:pipeline) { create(:ci_pipeline) }
before do before do
stub_ci_pipeline_yaml_file(config) stub_ci_pipeline_yaml_file(config)
end end
...@@ -1439,11 +1442,7 @@ describe Ci::Build do ...@@ -1439,11 +1442,7 @@ describe Ci::Build do
{ key: 'SECRET_KEY', value: 'secret_value', public: false } { key: 'SECRET_KEY', value: 'secret_value', public: false }
end end
let(:group) { create(:group, :access_requestable) }
before do before do
build.project.update(group: group)
create(:ci_group_variable, create(:ci_group_variable,
secret_variable.slice(:key, :value).merge(group: group)) secret_variable.slice(:key, :value).merge(group: group))
end end
...@@ -1456,11 +1455,7 @@ describe Ci::Build do ...@@ -1456,11 +1455,7 @@ describe Ci::Build do
{ key: 'PROTECTED_KEY', value: 'protected_value', public: false } { key: 'PROTECTED_KEY', value: 'protected_value', public: false }
end end
let(:group) { create(:group, :access_requestable) }
before do before do
build.project.update(group: group)
create(:ci_group_variable, create(:ci_group_variable,
:protected, :protected,
protected_variable.slice(:key, :value).merge(group: group)) protected_variable.slice(:key, :value).merge(group: group))
...@@ -1483,6 +1478,10 @@ describe Ci::Build do ...@@ -1483,6 +1478,10 @@ describe Ci::Build do
end end
context 'when the ref is not protected' do context 'when the ref is not protected' do
before do
build.update_column(:ref, 'some/feature')
end
it { is_expected.not_to include(protected_variable) } it { is_expected.not_to include(protected_variable) }
end end
end end
...@@ -1549,6 +1548,8 @@ describe Ci::Build do ...@@ -1549,6 +1548,8 @@ describe Ci::Build do
end end
context 'when yaml_variables are undefined' do context 'when yaml_variables are undefined' do
let(:pipeline) { create(:ci_pipeline, project: project) }
before do before do
build.yaml_variables = nil build.yaml_variables = nil
end end
...@@ -1642,7 +1643,10 @@ describe Ci::Build do ...@@ -1642,7 +1643,10 @@ describe Ci::Build do
before do before do
build.environment = 'production' build.environment = 'production'
allow(project).to receive(:deployment_variables).and_return([deployment_variable])
allow_any_instance_of(Project)
.to receive(:deployment_variables)
.and_return([deployment_variable])
end end
it { is_expected.to include(deployment_variable) } it { is_expected.to include(deployment_variable) }
...@@ -1666,14 +1670,19 @@ describe Ci::Build do ...@@ -1666,14 +1670,19 @@ describe Ci::Build do
before do before do
allow(build).to receive(:predefined_variables) { [build_pre_var] } allow(build).to receive(:predefined_variables) { [build_pre_var] }
allow(project).to receive(:predefined_variables) { [project_pre_var] }
allow(pipeline).to receive(:predefined_variables) { [pipeline_pre_var] }
allow(build).to receive(:yaml_variables) { [build_yaml_var] } allow(build).to receive(:yaml_variables) { [build_yaml_var] }
allow(project).to receive(:secret_variables_for) allow_any_instance_of(Project)
.to receive(:predefined_variables) { [project_pre_var] }
allow_any_instance_of(Project)
.to receive(:secret_variables_for)
.with(ref: 'master', environment: nil) do .with(ref: 'master', environment: nil) do
[create(:ci_variable, key: 'secret', value: 'value')] [create(:ci_variable, key: 'secret', value: 'value')]
end end
allow_any_instance_of(Ci::Pipeline)
.to receive(:predefined_variables) { [pipeline_pre_var] }
end end
it do it 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