Commit b9c745f0 authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch 'master' into 'master'

Update tag.rb

See merge request gitlab-org/gitlab!31858
parents 7ea4486a 48499b0d
......@@ -4,15 +4,15 @@ class Packages::Tag < ApplicationRecord
validates :package, :name, presence: true
TAGS_LIMIT = 200.freeze
FOR_PACKAGES_TAGS_LIMIT = 200.freeze
NUGET_TAGS_SEPARATOR = ' ' # https://docs.microsoft.com/en-us/nuget/reference/nuspec#tags
scope :preload_package, -> { preload(:package) }
scope :with_name, -> (name) { where(name: name) }
def self.for_packages(packages, max_tags_limit = TAGS_LIMIT)
def self.for_packages(packages)
where(package_id: packages.select(:id))
.order(updated_at: :desc)
.limit(max_tags_limit)
.limit(FOR_PACKAGES_TAGS_LIMIT)
end
end
---
title: Renaming TAGS_LIMIT constant to FOR_PACKAGES_TAGS_LIMIT
merge_request: 31858
author: Ashutosh Kumar Singh
type: change
......@@ -19,17 +19,18 @@ RSpec.describe Packages::Tag, type: :model do
describe '.for_packages' do
let(:package2) { create(:package, project: project, updated_at: 2.days.ago) }
let(:package3) { create(:package, project: project, updated_at: 1.day.ago) }
let(:tags_limit) { Packages::Tag::TAGS_LIMIT }
let!(:tag1) { create(:packages_tag, package: package) }
let!(:tag2) { create(:packages_tag, package: package2) }
let!(:tag3) { create(:packages_tag, package: package3) }
subject { described_class.for_packages(project.packages, tags_limit) }
subject { described_class.for_packages(project.packages) }
it { is_expected.to match_array([tag1, tag2, tag3]) }
context 'with too many tags' do
let(:tags_limit) { 2 }
before do
stub_const('Packages::Tag::FOR_PACKAGES_TAGS_LIMIT', 2)
end
it { is_expected.to match_array([tag2, tag3]) }
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