Commit 44cc1b9f authored by Pedro Pombeiro's avatar Pedro Pombeiro

Scope variable_inside_variable to project

parent 981ad651
...@@ -8,8 +8,9 @@ module Gitlab ...@@ -8,8 +8,9 @@ module Gitlab
include TSort include TSort
include Gitlab::Utils::StrongMemoize include Gitlab::Utils::StrongMemoize
def initialize(variables) def initialize(variables, project)
@variables = variables @variables = variables
@project = project
end end
def valid? def valid?
...@@ -19,7 +20,7 @@ module Gitlab ...@@ -19,7 +20,7 @@ module Gitlab
# errors sorts an array of variables, ignoring unknown variable references, # errors sorts an array of variables, ignoring unknown variable references,
# and returning an error string if a circular variable reference is found # and returning an error string if a circular variable reference is found
def errors def errors
return if Feature.disabled?(:variable_inside_variable) return if Feature.disabled?(:variable_inside_variable, @project)
strong_memoize(:errors) do strong_memoize(:errors) do
# Check for cyclic dependencies and build error message in that case # Check for cyclic dependencies and build error message in that case
...@@ -34,7 +35,7 @@ module Gitlab ...@@ -34,7 +35,7 @@ module Gitlab
# sort sorts an array of variables, ignoring unknown variable references. # sort sorts an array of variables, ignoring unknown variable references.
# If a circular variable reference is found, the original array is returned # If a circular variable reference is found, the original array is returned
def sort def sort
return @variables if Feature.disabled?(:variable_inside_variable) return @variables if Feature.disabled?(:variable_inside_variable, @project)
return @variables if errors return @variables if errors
tsort tsort
......
...@@ -5,8 +5,11 @@ require 'spec_helper' ...@@ -5,8 +5,11 @@ require 'spec_helper'
RSpec.describe Gitlab::Ci::Variables::Collection::Sorted do RSpec.describe Gitlab::Ci::Variables::Collection::Sorted do
describe '#errors' do describe '#errors' do
context 'when FF :variable_inside_variable is disabled' do context 'when FF :variable_inside_variable is disabled' do
let_it_be(:project_with_flag_disabled) { create(:project) }
let_it_be(:project_with_flag_enabled) { create(:project) }
before do before do
stub_feature_flags(variable_inside_variable: false) stub_feature_flags(variable_inside_variable: [project_with_flag_enabled])
end end
context 'table tests' do context 'table tests' do
...@@ -53,7 +56,7 @@ RSpec.describe Gitlab::Ci::Variables::Collection::Sorted do ...@@ -53,7 +56,7 @@ RSpec.describe Gitlab::Ci::Variables::Collection::Sorted do
end end
with_them do with_them do
subject { Gitlab::Ci::Variables::Collection::Sorted.new(variables) } subject { Gitlab::Ci::Variables::Collection::Sorted.new(variables, project_with_flag_disabled) }
it 'does not report error' do it 'does not report error' do
expect(subject.errors).to eq(nil) expect(subject.errors).to eq(nil)
...@@ -67,8 +70,11 @@ RSpec.describe Gitlab::Ci::Variables::Collection::Sorted do ...@@ -67,8 +70,11 @@ RSpec.describe Gitlab::Ci::Variables::Collection::Sorted do
end end
context 'when FF :variable_inside_variable is enabled' do context 'when FF :variable_inside_variable is enabled' do
let_it_be(:project_with_flag_disabled) { create(:project) }
let_it_be(:project_with_flag_enabled) { create(:project) }
before do before do
stub_feature_flags(variable_inside_variable: true) stub_feature_flags(variable_inside_variable: [project_with_flag_enabled])
end end
context 'table tests' do context 'table tests' do
...@@ -100,7 +106,7 @@ RSpec.describe Gitlab::Ci::Variables::Collection::Sorted do ...@@ -100,7 +106,7 @@ RSpec.describe Gitlab::Ci::Variables::Collection::Sorted do
end end
with_them do with_them do
subject { Gitlab::Ci::Variables::Collection::Sorted.new(variables) } subject { Gitlab::Ci::Variables::Collection::Sorted.new(variables, project_with_flag_enabled) }
it 'errors matches expected validation result' do it 'errors matches expected validation result' do
expect(subject.errors).to eq(validation_result) expect(subject.errors).to eq(validation_result)
...@@ -164,7 +170,8 @@ RSpec.describe Gitlab::Ci::Variables::Collection::Sorted do ...@@ -164,7 +170,8 @@ RSpec.describe Gitlab::Ci::Variables::Collection::Sorted do
end end
with_them do with_them do
subject { Gitlab::Ci::Variables::Collection::Sorted.new(variables) } let_it_be(:project) { create(:project) }
subject { Gitlab::Ci::Variables::Collection::Sorted.new(variables, project) }
it 'does not expand variables' do it 'does not expand variables' do
expect(subject.sort).to eq(variables) expect(subject.sort).to eq(variables)
...@@ -239,7 +246,8 @@ RSpec.describe Gitlab::Ci::Variables::Collection::Sorted do ...@@ -239,7 +246,8 @@ RSpec.describe Gitlab::Ci::Variables::Collection::Sorted do
end end
with_them do with_them do
subject { Gitlab::Ci::Variables::Collection::Sorted.new(variables) } let_it_be(:project) { create(:project) }
subject { Gitlab::Ci::Variables::Collection::Sorted.new(variables, project) }
it 'sort returns correctly sorted variables' do it 'sort returns correctly sorted variables' do
expect(subject.sort.map { |var| var[:key] }).to eq(result) expect(subject.sort.map { |var| var[:key] }).to eq(result)
......
...@@ -17,7 +17,7 @@ RSpec.describe Ci::BuildRunnerPresenter do ...@@ -17,7 +17,7 @@ RSpec.describe Ci::BuildRunnerPresenter do
describe '#artifacts' do describe '#artifacts' do
context "when option contains archive-type artifacts" do context "when option contains archive-type artifacts" do
let(:build) { create(:ci_build, options: { artifacts: archive } ) } let(:build) { create(:ci_build, options: { artifacts: archive }) }
it 'presents correct hash' do it 'presents correct hash' do
expect(presenter.artifacts.first).to include(archive_expectation) expect(presenter.artifacts.first).to include(archive_expectation)
...@@ -249,7 +249,7 @@ RSpec.describe Ci::BuildRunnerPresenter do ...@@ -249,7 +249,7 @@ RSpec.describe Ci::BuildRunnerPresenter do
it 'returns the correct refspecs' do it 'returns the correct refspecs' do
is_expected.to contain_exactly("+#{pipeline.sha}:refs/pipelines/#{pipeline.id}", is_expected.to contain_exactly("+#{pipeline.sha}:refs/pipelines/#{pipeline.id}",
"+refs/heads/#{build.ref}:refs/remotes/origin/#{build.ref}") "+refs/heads/#{build.ref}:refs/remotes/origin/#{build.ref}")
end end
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