diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-04-03 12:51:13 +0300 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-04-03 12:51:13 +0300 |
commit | 6fefa794304a6233368b592422ea0fb71a2700f0 (patch) | |
tree | df4483231f278753e380778695e82ffe25e687a2 | |
parent | e10dae3e3c2a5fb6077244c72e44c912b7281349 (diff) |
Validate uniqueness of container repository name
-rw-r--r-- | app/models/container_repository.rb | 1 | ||||
-rw-r--r-- | spec/models/container_repository_spec.rb | 7 |
2 files changed, 8 insertions, 0 deletions
diff --git a/app/models/container_repository.rb b/app/models/container_repository.rb index ab04258ab8d..0cf781799e9 100644 --- a/app/models/container_repository.rb +++ b/app/models/container_repository.rb @@ -2,6 +2,7 @@ class ContainerRepository < ActiveRecord::Base belongs_to :project validates :name, length: { minimum: 0, allow_nil: false } + validates :name, uniqueness: { scope: :project_id } delegate :client, to: :registry diff --git a/spec/models/container_repository_spec.rb b/spec/models/container_repository_spec.rb index f794085fc45..503da6556c0 100644 --- a/spec/models/container_repository_spec.rb +++ b/spec/models/container_repository_spec.rb @@ -21,6 +21,13 @@ describe ContainerRepository do headers: { 'Content-Type' => 'application/json' }) end + describe 'validations' do + it 'validates uniqueness of name scoped to project' do + expect(subject).to validate_uniqueness_of(:name) + .scoped_to(:project_id) + end + end + describe 'associations' do it 'belongs to the project' do expect(container_repository).to belong_to(:project) |