Commit 45808ab7 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Adopt changes from moving environment_scope in CE

parent 443f1031
......@@ -3,15 +3,11 @@ module Ci
extend Ci::Model
prepend EE::Ci::Variable
def self.key_uniqueness_scope
:project_id
end
belongs_to :project
validates :key,
presence: true,
uniqueness: { scope: key_uniqueness_scope },
uniqueness: { scope: [:project_id, :environment_scope] },
length: { maximum: 255 },
format: { with: /\A[a-zA-Z0-9_]+\z/,
message: "can contain only letters, digits and '_'." }
......
......@@ -3,12 +3,6 @@ module EE
module Variable
extend ActiveSupport::Concern
module ClassMethods
def key_uniqueness_scope
%i[project_id environment_scope]
end
end
prepended do
validates(
:environment_scope,
......
......@@ -5,11 +5,19 @@ describe Ci::Variable, models: true do
let(:secret_value) { 'secret' }
describe 'validations' do
# EE
before do
stub_feature(:variable_environment_scope)
end
it { is_expected.to validate_presence_of(:key) }
it { is_expected.to validate_uniqueness_of(:key).scoped_to(:project_id, :environment_scope) }
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) }
end
describe '.unprotected' do
subject { described_class.unprotected }
......
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