diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2017-05-26 20:46:57 +0300 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2017-05-26 20:46:57 +0300 |
commit | 2785bc4faa0eb5c46b0c8b46b77aa4cf1d4ee4b4 (patch) | |
tree | 2b53225328d3d32341a54124466a0a4084b9d0c8 /spec/models/project_spec.rb | |
parent | 9cc918a5caca931887026d258ea1dcd6499d7c2f (diff) |
Merge secret and protected vars to variables_for(ref)
Also introduce Ci::Variable#to_runner_variable to
build up the hash for runner.
Diffstat (limited to 'spec/models/project_spec.rb')
-rw-r--r-- | spec/models/project_spec.rb | 42 |
1 files changed, 30 insertions, 12 deletions
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index b9094387865..7e5e6e899e2 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -1710,7 +1710,7 @@ describe Project, models: true do end end - describe 'variables' do + describe '#variables_for' do let(:project) { create(:empty_project) } let!(:secret_variable) do @@ -1721,22 +1721,40 @@ describe Project, models: true do create(:ci_variable, :protected, value: 'protected', project: project) end - describe '#secret_variables' do + subject { project.variables_for('ref') } + + shared_examples 'ref is protected' do + it 'contains all the variables' do + is_expected.to contain_exactly( + *[secret_variable, protected_variable].map(&:to_runner_variable)) + end + end + + context 'when the ref is not protected' do + before do + stub_application_setting( + default_branch_protection: Gitlab::Access::PROTECTION_NONE) + end + it 'contains only the secret variables' do - expect(project.secret_variables).to eq( - [{ key: secret_variable.key, - value: secret_variable.value, - public: false }]) + is_expected.to contain_exactly(secret_variable.to_runner_variable) end end - describe '#protected_variables' do - it 'contains only the protected variables' do - expect(project.protected_variables).to eq( - [{ key: protected_variable.key, - value: protected_variable.value, - public: false }]) + context 'when the ref is a protected branch' do + before do + create(:protected_branch, name: 'ref', project: project) end + + it_behaves_like 'ref is protected' + end + + context 'when the ref is a protected tag' do + before do + create(:protected_tag, name: 'ref', project: project) + end + + it_behaves_like 'ref is protected' end end |