Commit 6434a36e authored by James Lopez's avatar James Lopez

Merge branch '32035-bug-dedup-licenses-dl' into 'master'

Resolve "Remove duplication of Licenses in Dependency List page"

See merge request gitlab-org/gitlab!16946
parents 147ad7a8 8f944bb9
---
title: Remove duplication of Licenses in Dependency List page
merge_request: 16946
author:
type: fixed
......@@ -18,6 +18,7 @@ module Gitlab
def apply_license(license)
dependencies.each do |dependency|
next unless dependency[:name] == license[:dependency][:name]
next if dependency[:licenses].include?(license[:license])
dependency[:licenses] << license[:license]
end
......
......@@ -16,4 +16,51 @@ describe Gitlab::Ci::Reports::DependencyList::Report do
expect(report.dependencies).to eq([dependency])
end
end
describe '#apply_license' do
subject { report.dependencies.last[:licenses].size }
let(:license) do
{
dependency: {
name: 'nokogiri'
},
license: {
name: 'MIT',
url: 'http://opensource.org/licenses/mit-license'
}
}
end
before do
report.add_dependency(dependency)
report.apply_license(license)
end
context 'with matching dependency' do
context 'with empty license list' do
let(:dependency) { build :dependency }
it 'applies license' do
is_expected.to eq(1)
end
end
context 'with full license list' do
let(:dependency) { build :dependency, :with_licenses }
it 'does not apply the license a second time' do
is_expected.to eq(1)
end
end
end
context 'without matching dependency' do
let(:dependency) { build :dependency, name: 'irigokon' }
it 'does not apply the license at all' do
is_expected.to eq(0)
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