Commit 8f944bb9 authored by Tetiana Chupryna's avatar Tetiana Chupryna Committed by James Lopez

Resolve "Remove duplication of Licenses in Dependency List page"

parent 147ad7a8
---
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