Commit 16475490 authored by Vijay Hawoldar's avatar Vijay Hawoldar

Add validation to additional pack purchase_xid

For GitLab.com we should attempt to ensure the uniqueness
of Ci::Minutes::AdditionalPack purchase_xid values

Changelog: changed
EE: true
parent fe964d08
......@@ -15,6 +15,7 @@ module Ci
validates :namespace, :number_of_minutes, presence: true
validates :expires_at, :purchase_xid, presence: true, if: -> { ::Gitlab.com? }
validates :purchase_xid, length: { maximum: 32 }
validates :purchase_xid, uniqueness: true, if: -> { ::Gitlab.com? }
end
end
end
......@@ -8,6 +8,8 @@ RSpec.describe Ci::Minutes::AdditionalPack do
end
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(:number_of_minutes) }
it { is_expected.to validate_length_of(:purchase_xid).is_at_most(32) }
......@@ -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(:purchase_xid) }
it { is_expected.to validate_uniqueness_of(:purchase_xid) }
end
context 'when self-managed' 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(:expires_at) }
it { is_expected.not_to validate_uniqueness_of(:purchase_xid) }
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