2019-03-30 07:23:56 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-08-26 01:42:46 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 18:09:03 +00:00
|
|
|
RSpec.describe Ci::Variable do
|
2017-05-08 19:56:37 +00:00
|
|
|
subject { build(:ci_variable) }
|
2015-08-26 01:42:46 +00:00
|
|
|
|
2019-05-06 13:11:42 +00:00
|
|
|
it_behaves_like "CI variable"
|
|
|
|
|
2017-06-21 17:30:12 +00:00
|
|
|
describe 'validations' do
|
2017-05-03 18:51:55 +00:00
|
|
|
it { is_expected.to include_module(Presentable) }
|
2020-03-18 12:09:13 +00:00
|
|
|
it { is_expected.to include_module(Ci::Maskable) }
|
2019-08-08 18:51:52 +00:00
|
|
|
it { is_expected.to include_module(HasEnvironmentScope) }
|
2018-02-23 00:19:46 +00:00
|
|
|
it { is_expected.to validate_uniqueness_of(:key).scoped_to(:project_id, :environment_scope).with_message(/\(\w+\) has already been taken/) }
|
2017-06-21 17:30:12 +00:00
|
|
|
end
|
2016-12-02 12:54:57 +00:00
|
|
|
|
2017-06-01 13:48:31 +00:00
|
|
|
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
|
2015-08-26 01:42:46 +00:00
|
|
|
end
|
|
|
|
end
|