Commit 50768a25 authored by Shinya Maeda's avatar Shinya Maeda

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

Add test

Add changelog
parent ba5a9033
......@@ -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