From 41aebaa103a8c9ef6ae5edef5cc500ba6ca24bb9 Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Mon, 26 Jun 2017 22:03:34 +0900 Subject: Decuplin --- spec/models/ci/variable_spec.rb | 40 +--------------------------------------- 1 file changed, 1 insertion(+), 39 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 83494af24ba..ade279cd16f 100644 --- a/spec/models/ci/variable_spec.rb +++ b/spec/models/ci/variable_spec.rb @@ -3,14 +3,8 @@ require 'spec_helper' describe Ci::Variable, models: true do subject { build(:ci_variable) } - let(:secret_value) { 'secret' } - - it { is_expected.to validate_presence_of(:key) } + it { is_expected.to be_kind_of(HasVariable) } it { is_expected.to validate_uniqueness_of(:key).scoped_to(:project_id) } - it { is_expected.to validate_length_of(:key).is_at_most(255) } - it { is_expected.to allow_value('foo').for(:key) } - it { is_expected.not_to allow_value('foo bar').for(:key) } - it { is_expected.not_to allow_value('foo/bar').for(:key) } describe '.unprotected' do subject { described_class.unprotected } @@ -33,36 +27,4 @@ describe Ci::Variable, models: true do 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 - - it 'stores an iv for value' do - expect(subject.encrypted_value_iv).not_to be_nil - end - - it 'stores a salt for value' do - expect(subject.encrypted_value_salt).not_to be_nil - end - - it 'fails to decrypt if iv is incorrect' do - subject.encrypted_value_iv = SecureRandom.hex - subject.instance_variable_set(:@value, nil) - expect { subject.value } - .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 083179e936dba669085cda7bb159c10be4d9312a Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Tue, 27 Jun 2017 00:12:52 +0900 Subject: Add a test for checking validates :key does not override by concern --- spec/models/ci/variable_spec.rb | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 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 ade279cd16f..b7821afbdc9 100644 --- a/spec/models/ci/variable_spec.rb +++ b/spec/models/ci/variable_spec.rb @@ -6,6 +6,40 @@ describe Ci::Variable, models: true do it { is_expected.to be_kind_of(HasVariable) } it { is_expected.to validate_uniqueness_of(:key).scoped_to(:project_id) } + describe 'validates :key' do + let(:project) { create(:project) } + + it 'be invalid if it exceeds maximum' do + expect do + create(:ci_variable, project: project, key: "A"*256) + end.to raise_error(ActiveRecord::RecordInvalid) + end + + it 'be invalid if violates constraints' do + expect do + create(:ci_variable, project: project, key: "*") + end.to raise_error(ActiveRecord::RecordInvalid) + end + + context 'when there is a variable' do + before do + create(:ci_variable, key: 'AAA', project: project) + end + + it 'be valid if it is unique' do + expect do + create(:ci_variable, project: project, key: 'CCC') + end.not_to raise_error + end + + it 'be invalid if it is duplicated' do + expect do + create(:ci_variable, project: project, key: 'AAA') + end.to raise_error(ActiveRecord::RecordInvalid) + end + end + end + describe '.unprotected' do subject { described_class.unprotected } -- cgit v1.2.1 From 2633a635311f60d15d9729dc770fdf2324a67927 Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Tue, 27 Jun 2017 19:25:31 +0900 Subject: Remove PoC spec --- spec/models/ci/variable_spec.rb | 34 ---------------------------------- 1 file changed, 34 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 b7821afbdc9..ade279cd16f 100644 --- a/spec/models/ci/variable_spec.rb +++ b/spec/models/ci/variable_spec.rb @@ -6,40 +6,6 @@ describe Ci::Variable, models: true do it { is_expected.to be_kind_of(HasVariable) } it { is_expected.to validate_uniqueness_of(:key).scoped_to(:project_id) } - describe 'validates :key' do - let(:project) { create(:project) } - - it 'be invalid if it exceeds maximum' do - expect do - create(:ci_variable, project: project, key: "A"*256) - end.to raise_error(ActiveRecord::RecordInvalid) - end - - it 'be invalid if violates constraints' do - expect do - create(:ci_variable, project: project, key: "*") - end.to raise_error(ActiveRecord::RecordInvalid) - end - - context 'when there is a variable' do - before do - create(:ci_variable, key: 'AAA', project: project) - end - - it 'be valid if it is unique' do - expect do - create(:ci_variable, project: project, key: 'CCC') - end.not_to raise_error - end - - it 'be invalid if it is duplicated' do - expect do - create(:ci_variable, project: project, key: 'AAA') - end.to raise_error(ActiveRecord::RecordInvalid) - end - end - end - describe '.unprotected' do subject { described_class.unprotected } -- cgit v1.2.1 From de893b19c30acf83ce43dd42376783505d704763 Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Wed, 28 Jun 2017 15:25:36 +0900 Subject: Improve small things --- spec/models/ci/variable_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (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 ade279cd16f..329682a0771 100644 --- a/spec/models/ci/variable_spec.rb +++ b/spec/models/ci/variable_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe Ci::Variable, models: true do subject { build(:ci_variable) } - it { is_expected.to be_kind_of(HasVariable) } + it { is_expected.to include_module(HasVariable) } it { is_expected.to validate_uniqueness_of(:key).scoped_to(:project_id) } describe '.unprotected' do -- cgit v1.2.1