Commit 12160237 authored by mo khan's avatar mo khan

Correct licenses with invalid spdx identifier

parent 22065fbe
...@@ -8,8 +8,8 @@ class ImportSoftwareLicensesWorker ...@@ -8,8 +8,8 @@ class ImportSoftwareLicensesWorker
def perform def perform
catalogue.each do |spdx_license| catalogue.each do |spdx_license|
if unknown_licenses[spdx_license.name] if licenses[spdx_license.name]
unknown_licenses_with(spdx_license.name) licenses_with(spdx_license.name)
.update_all(spdx_identifier: spdx_license.id) .update_all(spdx_identifier: spdx_license.id)
else else
SoftwareLicense.safe_find_or_create_by!( SoftwareLicense.safe_find_or_create_by!(
...@@ -22,13 +22,13 @@ class ImportSoftwareLicensesWorker ...@@ -22,13 +22,13 @@ class ImportSoftwareLicensesWorker
private private
def unknown_licenses def licenses
@unknown_licenses ||= @licenses ||=
unknown_licenses_with(catalogue.map(&:name)).grouped_by_name.count licenses_with(catalogue.map(&:name)).grouped_by_name.count
end end
def unknown_licenses_with(name) def licenses_with(name)
SoftwareLicense.unknown.by_name(name) SoftwareLicense.by_name(name)
end end
def catalogue def catalogue
......
...@@ -39,5 +39,15 @@ describe ImportSoftwareLicensesWorker do ...@@ -39,5 +39,15 @@ describe ImportSoftwareLicensesWorker do
expect { subject.perform }.not_to change(SoftwareLicense, :count) expect { subject.perform }.not_to change(SoftwareLicense, :count)
end end
end end
context 'when a license has an invalid SPDX identifier' do
before do
apache.update_column(:spdx_identifier, 'invalid')
subject.perform
end
it { expect(apache.reload.spdx_identifier).to eql(spdx_apache_license.id) }
it { expect(SoftwareLicense.pluck(:spdx_identifier)).to contain_exactly(spdx_apache_license.id, spdx_mit_license.id, spdx_bsd_license.id) }
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