Commit dce04a92 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'add-uniqueness-validation-to-url-column-in-releases-link-model' into 'master'

Add uniqueness validation to url column in Releases::Link model

Closes #55929

See merge request gitlab-org/gitlab-ce!24223
parents bdc1ebd0 50768a25
......@@ -6,7 +6,7 @@ module Releases
belongs_to :release
validates :url, presence: true, url: true
validates :url, presence: true, url: true, uniqueness: { scope: :release }
validates :name, presence: true, uniqueness: { scope: :release }
scope :sorted, -> { order(created_at: :desc) }
......
---
title: Add uniqueness validation to url column in Releases::Link model
merge_request: 24223
author:
type: other
......@@ -31,6 +31,16 @@ describe Releases::Link do
end.to raise_error(ActiveRecord::RecordInvalid)
end
end
context 'when duplicate url is added to a release' do
let!(:link) { create(:release_link, url: 'http://gitlab.com', release: release) }
it 'raises an error' do
expect do
create(:release_link, url: 'http://gitlab.com', release: release)
end.to raise_error(ActiveRecord::RecordInvalid)
end
end
end
describe '.sorted' do
......
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