Commit 8a14548f authored by Shinya Maeda's avatar Shinya Maeda

Add spec for duplicate link name creation

Fix spec for mysql unique validation failure
parent f5f52da8
...@@ -48,7 +48,7 @@ module Releases ...@@ -48,7 +48,7 @@ module Releases
) )
success(tag: tag, release: release) success(tag: tag, release: release)
rescue ActiveRecord::RecordInvalid => e rescue => e
error(e.message, 400) error(e.message, 400)
end end
end end
......
...@@ -153,6 +153,7 @@ describe API::Releases do ...@@ -153,6 +153,7 @@ describe API::Releases do
get api("/projects/#{project.id}/releases/v0.1", maintainer) get api("/projects/#{project.id}/releases/v0.1", maintainer)
expect(json_response['assets']['links'].count).to eq(1) expect(json_response['assets']['links'].count).to eq(1)
expect(json_response['assets']['links'].first['id']).to eq(link.id)
expect(json_response['assets']['links'].first['name']) expect(json_response['assets']['links'].first['name'])
.to eq('release-18.04.dmg') .to eq('release-18.04.dmg')
expect(json_response['assets']['links'].first['url']) expect(json_response['assets']['links'].first['url'])
...@@ -303,19 +304,21 @@ describe API::Releases do ...@@ -303,19 +304,21 @@ describe API::Releases do
end end
context 'when create assets altogether' do context 'when create assets altogether' do
let(:base_params) do
{
name: 'New release',
tag_name: 'v0.1',
description: 'Super nice release'
}
end
context 'when create one asset' do context 'when create one asset' do
let(:params) do let(:params) do
{ base_params.merge({
name: 'New release',
tag_name: 'v0.1',
description: 'Super nice release',
links_attributes: [ links_attributes: [
{ { name: 'beta', url: 'https://dosuken.example.com/inspection.exe' }
name: 'beta',
url: 'https://dosuken.example.com/inspection.exe'
}
] ]
} })
end end
it 'accepts the request' do it 'accepts the request' do
...@@ -342,21 +345,12 @@ describe API::Releases do ...@@ -342,21 +345,12 @@ describe API::Releases do
context 'when create two assets' do context 'when create two assets' do
let(:params) do let(:params) do
{ base_params.merge({
name: 'New release',
tag_name: 'v0.1',
description: 'Super nice release',
links_attributes: [ links_attributes: [
{ { name: 'alpha', url: 'https://dosuken.example.com/alpha.exe' },
name: 'alpha', { name: 'beta', url: 'https://dosuken.example.com/beta.exe' }
url: 'https://dosuken.example.com/alpha.exe'
},
{
name: 'beta',
url: 'https://dosuken.example.com/beta.exe'
}
] ]
} })
end end
it 'creates two assets with specified parameters' do it 'creates two assets with specified parameters' do
...@@ -369,6 +363,23 @@ describe API::Releases do ...@@ -369,6 +363,23 @@ describe API::Releases do
.to match_array(%w[https://dosuken.example.com/alpha.exe .to match_array(%w[https://dosuken.example.com/alpha.exe
https://dosuken.example.com/beta.exe]) https://dosuken.example.com/beta.exe])
end end
context 'when link names are duplicates' do
let(:params) do
base_params.merge({
links_attributes: [
{ name: 'alpha', url: 'https://dosuken.example.com/alpha.exe' },
{ name: 'alpha', url: 'https://dosuken.example.com/beta.exe' }
]
})
end
it 'recognizes as a bad request' do
post api("/projects/#{project.id}/releases", maintainer), params: params
expect(response).to have_gitlab_http_status(:bad_request)
end
end
end end
end 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