Skip to content
代码片段 群组 项目
未验证 提交 6f51842b 编辑于 作者: Omar Qunsul's avatar Omar Qunsul 提交者: GitLab
浏览文件

Merge branch 'mc_rocha-fix-missing-entries-license-list-473181' into 'master'

No related branches found
No related tags found
无相关合并请求
...@@ -8,6 +8,7 @@ class SoftwareLicense < ApplicationRecord ...@@ -8,6 +8,7 @@ class SoftwareLicense < ApplicationRecord
TransactionInProgressError = Class.new(StandardError) TransactionInProgressError = Class.new(StandardError)
ALL_LICENSE_NAMES_CACHE_KEY = [name, 'all_license_names'].freeze ALL_LICENSE_NAMES_CACHE_KEY = [name, 'all_license_names'].freeze
TRANSACTION_MESSAGE = "Sub-transactions are not allowed as there is already an open transaction." TRANSACTION_MESSAGE = "Sub-transactions are not allowed as there is already an open transaction."
LICENSE_LIMIT = 1_000
validates :name, presence: true, uniqueness: true validates :name, presence: true, uniqueness: true
validates :spdx_identifier, length: { maximum: 255 } validates :spdx_identifier, length: { maximum: 255 }
...@@ -18,13 +19,9 @@ class SoftwareLicense < ApplicationRecord ...@@ -18,13 +19,9 @@ class SoftwareLicense < ApplicationRecord
scope :spdx, -> { where.not(spdx_identifier: nil) } scope :spdx, -> { where.not(spdx_identifier: nil) }
scope :unknown, -> { where(spdx_identifier: nil) } scope :unknown, -> { where(spdx_identifier: nil) }
scope :grouped_by_name, -> { group(:name) } scope :grouped_by_name, -> { group(:name) }
scope :unreachable_limit, -> { limit(500) } scope :unreachable_limit, -> { limit(LICENSE_LIMIT) }
class << self class << self
def unclassified_licenses_for(project)
spdx.id_not_in(project.software_licenses).ordered.unreachable_limit
end
def all_license_names def all_license_names
Rails.cache.fetch(ALL_LICENSE_NAMES_CACHE_KEY, expires_in: 7.days) do Rails.cache.fetch(ALL_LICENSE_NAMES_CACHE_KEY, expires_in: 7.days) do
spdx.ordered.unreachable_limit.pluck_names spdx.ordered.unreachable_limit.pluck_names
......
...@@ -74,29 +74,6 @@ ...@@ -74,29 +74,6 @@
end end
end end
describe '.unclassified_licenses_for' do
subject { described_class.unclassified_licenses_for(project) }
let_it_be(:mit_license) { create(:software_license, :mit) }
let_it_be(:apache_license) { create(:software_license, :apache_2_0) }
let_it_be(:nonstandard_license) { create(:software_license, :user_entered) }
let_it_be(:project) { create(:project) }
context 'when a project has not classified licenses' do
it 'returns each license in the SPDX catalogue ordered by name' do
expect(subject.to_a).to eql([apache_license, mit_license])
end
end
context 'when some of the licenses are classified' do
let_it_be(:mit_policy) { create(:software_license_policy, project: project, software_license: mit_license) }
it 'returns each license in the SPDX catalogue that has not been classified' do
expect(subject).to contain_exactly(apache_license)
end
end
end
describe '.all_license_names' do describe '.all_license_names' do
subject { described_class.all_license_names } subject { described_class.all_license_names }
...@@ -113,5 +90,15 @@ ...@@ -113,5 +90,15 @@
subject subject
end end
context 'when the number of spdx licenses exceeds the limit' do
before do
stub_const("#{described_class}::LICENSE_LIMIT", 1)
end
it 'returns ordered list of license names from the SPDX catalogue within the limit' do
expect(subject.to_a).to eql([apache_license.name])
end
end
end end
end end
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册