From 2785bc4faa0eb5c46b0c8b46b77aa4cf1d4ee4b4 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Sat, 27 May 2017 01:46:57 +0800 Subject: Merge secret and protected vars to variables_for(ref) Also introduce Ci::Variable#to_runner_variable to build up the hash for runner. --- spec/models/ci/variable_spec.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'spec/models/ci/variable_spec.rb') diff --git a/spec/models/ci/variable_spec.rb b/spec/models/ci/variable_spec.rb index fe8c52d5353..38b869f59ae 100644 --- a/spec/models/ci/variable_spec.rb +++ b/spec/models/ci/variable_spec.rb @@ -36,4 +36,11 @@ describe Ci::Variable, models: true do to raise_error(OpenSSL::Cipher::CipherError, 'bad decrypt') end end + + describe '#to_runner_variable' do + it 'returns a hash for the runner' do + expect(subject.to_runner_variable) + .to eq(key: subject.key, value: subject.value, public: false) + end + end end -- cgit v1.2.1 From 7da88278c33d20d97cf0eabb76b3117219479d12 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Thu, 1 Jun 2017 21:48:31 +0800 Subject: Make sure protected can't be null; Test protected! --- spec/models/ci/variable_spec.rb | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'spec/models/ci/variable_spec.rb') diff --git a/spec/models/ci/variable_spec.rb b/spec/models/ci/variable_spec.rb index 38b869f59ae..077b10227d7 100644 --- a/spec/models/ci/variable_spec.rb +++ b/spec/models/ci/variable_spec.rb @@ -12,11 +12,33 @@ describe Ci::Variable, models: true do it { is_expected.not_to allow_value('foo bar').for(:key) } it { is_expected.not_to allow_value('foo/bar').for(:key) } - before :each do - subject.value = secret_value + describe '.unprotected' do + subject { described_class.unprotected } + + context 'when variable is protected' do + before do + create(:ci_variable, :protected) + end + + it 'returns nothing' do + is_expected.to be_empty + end + end + + context 'when variable is not protected' do + let(:variable) { create(:ci_variable, protected: false) } + + it 'returns the variable' do + is_expected.to contain_exactly(variable) + end + end end describe '#value' do + before do + subject.value = secret_value + end + it 'stores the encrypted value' do expect(subject.encrypted_value).not_to be_nil end -- cgit v1.2.1