Commit d69dfcee authored by Etienne Baqué's avatar Etienne Baqué

Merge branch 'vij-additional-pack-uniqueness' into 'master'

Add unique validation to additional pack purchase_xid

See merge request gitlab-org/gitlab!63866
parents 94a83199 16475490
...@@ -15,6 +15,7 @@ module Ci ...@@ -15,6 +15,7 @@ module Ci
validates :namespace, :number_of_minutes, presence: true validates :namespace, :number_of_minutes, presence: true
validates :expires_at, :purchase_xid, presence: true, if: -> { ::Gitlab.com? } validates :expires_at, :purchase_xid, presence: true, if: -> { ::Gitlab.com? }
validates :purchase_xid, length: { maximum: 32 } validates :purchase_xid, length: { maximum: 32 }
validates :purchase_xid, uniqueness: true, if: -> { ::Gitlab.com? }
end end
end end
end end
...@@ -8,6 +8,8 @@ RSpec.describe Ci::Minutes::AdditionalPack do ...@@ -8,6 +8,8 @@ RSpec.describe Ci::Minutes::AdditionalPack do
end end
describe 'validations' do describe 'validations' do
subject(:additional_pack) { build(:ci_minutes_additional_pack) }
it { is_expected.to validate_presence_of(:namespace) } it { is_expected.to validate_presence_of(:namespace) }
it { is_expected.to validate_presence_of(:number_of_minutes) } it { is_expected.to validate_presence_of(:number_of_minutes) }
it { is_expected.to validate_length_of(:purchase_xid).is_at_most(32) } it { is_expected.to validate_length_of(:purchase_xid).is_at_most(32) }
...@@ -19,6 +21,7 @@ RSpec.describe Ci::Minutes::AdditionalPack do ...@@ -19,6 +21,7 @@ RSpec.describe Ci::Minutes::AdditionalPack do
it { is_expected.to validate_presence_of(:expires_at) } it { is_expected.to validate_presence_of(:expires_at) }
it { is_expected.to validate_presence_of(:purchase_xid) } it { is_expected.to validate_presence_of(:purchase_xid) }
it { is_expected.to validate_uniqueness_of(:purchase_xid) }
end end
context 'when self-managed' do context 'when self-managed' do
...@@ -28,6 +31,7 @@ RSpec.describe Ci::Minutes::AdditionalPack do ...@@ -28,6 +31,7 @@ RSpec.describe Ci::Minutes::AdditionalPack do
it { is_expected.not_to validate_presence_of(:purchase_xid) } it { is_expected.not_to validate_presence_of(:purchase_xid) }
it { is_expected.not_to validate_presence_of(:expires_at) } it { is_expected.not_to validate_presence_of(:expires_at) }
it { is_expected.not_to validate_uniqueness_of(:purchase_xid) }
end end
end end
end end
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