BigW Consortium Gitlab

Commit 6fefa794 by Grzegorz Bizon

Validate uniqueness of container repository name

parent e10dae3e
...@@ -2,6 +2,7 @@ class ContainerRepository < ActiveRecord::Base ...@@ -2,6 +2,7 @@ class ContainerRepository < ActiveRecord::Base
belongs_to :project belongs_to :project
validates :name, length: { minimum: 0, allow_nil: false } validates :name, length: { minimum: 0, allow_nil: false }
validates :name, uniqueness: { scope: :project_id }
delegate :client, to: :registry delegate :client, to: :registry
......
...@@ -21,6 +21,13 @@ describe ContainerRepository do ...@@ -21,6 +21,13 @@ describe ContainerRepository do
headers: { 'Content-Type' => 'application/json' }) headers: { 'Content-Type' => 'application/json' })
end 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 describe 'associations' do
it 'belongs to the project' do it 'belongs to the project' do
expect(container_repository).to belong_to(:project) expect(container_repository).to belong_to(:project)
......
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