Commit 756cb64a authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'pedropombeiro/26345-variable_inside_variable-scoped-FF' into 'master'

Scope variable_inside_variable to project

See merge request gitlab-org/gitlab!52811
parents 5dabb296 44cc1b9f
......@@ -8,8 +8,9 @@ module Gitlab
include TSort
include Gitlab::Utils::StrongMemoize
def initialize(variables)
def initialize(variables, project)
@variables = variables
@project = project
end
def valid?
......@@ -19,7 +20,7 @@ module Gitlab
# errors sorts an array of variables, ignoring unknown variable references,
# and returning an error string if a circular variable reference is found
def errors
return if Feature.disabled?(:variable_inside_variable)
return if Feature.disabled?(:variable_inside_variable, @project)
strong_memoize(:errors) do
# Check for cyclic dependencies and build error message in that case
......@@ -34,7 +35,7 @@ module Gitlab
# sort sorts an array of variables, ignoring unknown variable references.
# If a circular variable reference is found, the original array is returned
def sort
return @variables if Feature.disabled?(:variable_inside_variable)
return @variables if Feature.disabled?(:variable_inside_variable, @project)
return @variables if errors
tsort
......
......@@ -5,8 +5,11 @@ require 'spec_helper'
RSpec.describe Gitlab::Ci::Variables::Collection::Sorted do
describe '#errors' 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
stub_feature_flags(variable_inside_variable: false)
stub_feature_flags(variable_inside_variable: [project_with_flag_enabled])
end
context 'table tests' do
......@@ -53,7 +56,7 @@ RSpec.describe Gitlab::Ci::Variables::Collection::Sorted do
end
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
expect(subject.errors).to eq(nil)
......@@ -67,8 +70,11 @@ RSpec.describe Gitlab::Ci::Variables::Collection::Sorted do
end
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
stub_feature_flags(variable_inside_variable: true)
stub_feature_flags(variable_inside_variable: [project_with_flag_enabled])
end
context 'table tests' do
......@@ -100,7 +106,7 @@ RSpec.describe Gitlab::Ci::Variables::Collection::Sorted do
end
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
expect(subject.errors).to eq(validation_result)
......@@ -164,7 +170,8 @@ RSpec.describe Gitlab::Ci::Variables::Collection::Sorted do
end
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
expect(subject.sort).to eq(variables)
......@@ -239,7 +246,8 @@ RSpec.describe Gitlab::Ci::Variables::Collection::Sorted do
end
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
expect(subject.sort.map { |var| var[:key] }).to eq(result)
......
......@@ -17,7 +17,7 @@ RSpec.describe Ci::BuildRunnerPresenter do
describe '#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
expect(presenter.artifacts.first).to include(archive_expectation)
......
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