Commit 1c1d4a2f authored by Lin Jen-Shin's avatar Lin Jen-Shin

Merge branch '9047-duplicate-maven-result-should-be-hidden' into 'master'

Resolve "Duplicate Maven result should be hidden"

Closes #9047

See merge request gitlab-org/gitlab-ee!9151
parents 0a3c6915 36ca9057
...@@ -8,7 +8,7 @@ module Projects ...@@ -8,7 +8,7 @@ module Projects
before_action :authorize_destroy_package!, only: [:destroy] before_action :authorize_destroy_package!, only: [:destroy]
def index def index
@packages = project.packages.all.page(params[:page]) @packages = project.packages.has_version.page(params[:page])
end end
def show def show
......
...@@ -15,6 +15,7 @@ class Packages::Package < ActiveRecord::Base ...@@ -15,6 +15,7 @@ class Packages::Package < ActiveRecord::Base
enum package_type: { maven: 1, npm: 2 } enum package_type: { maven: 1, npm: 2 }
scope :with_name, ->(name) { where(name: name) } scope :with_name, ->(name) { where(name: name) }
scope :has_version, -> { where.not(version: nil) }
scope :preload_files, -> { preload(:package_files) } scope :preload_files, -> { preload(:package_files) }
scope :last_of_each_version, -> { where(id: all.select('MAX(id) AS id').group(:version)) } scope :last_of_each_version, -> { where(id: all.select('MAX(id) AS id').group(:version)) }
......
---
title: Hide packages without version from UI
merge_request: 9151
author:
type: fixed
...@@ -56,6 +56,14 @@ describe 'Packages' do ...@@ -56,6 +56,14 @@ describe 'Packages' do
expect(page).to have_content(package.version) expect(page).to have_content(package.version)
end end
it 'hides a package without a version from the list' do
package.update!(version: nil)
visit_project_packages
expect(page).not_to have_content(package.name)
end
it 'shows a single package' do it 'shows a single package' do
click_on package.name click_on package.name
......
...@@ -44,4 +44,16 @@ RSpec.describe Packages::Package, type: :model do ...@@ -44,4 +44,16 @@ RSpec.describe Packages::Package, type: :model do
is_expected.not_to include(package2) is_expected.not_to include(package2)
end end
end end
describe '.has_version' do
let!(:package1) { create(:npm_package, version: '1.0.0') }
let!(:package2) { create(:npm_package, version: nil) }
let!(:package3) { create(:npm_package, version: '1.0.1') }
subject { described_class.has_version }
it 'includes only packages with version attribute' do
is_expected.to match_array([package1, package3])
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