Commit d7f7bdde authored by Steve Abrams's avatar Steve Abrams

Add error status to package model

parent c98d7517
...@@ -5,6 +5,8 @@ class Packages::Package < ApplicationRecord ...@@ -5,6 +5,8 @@ class Packages::Package < ApplicationRecord
include UsageStatistics include UsageStatistics
include Gitlab::Utils::StrongMemoize include Gitlab::Utils::StrongMemoize
DISPLAYABLE_STATUSES = [:default, :error].freeze
belongs_to :project belongs_to :project
belongs_to :creator, class_name: 'User' belongs_to :creator, class_name: 'User'
...@@ -70,7 +72,7 @@ class Packages::Package < ApplicationRecord ...@@ -70,7 +72,7 @@ class Packages::Package < ApplicationRecord
composer: 6, generic: 7, golang: 8, debian: 9, composer: 6, generic: 7, golang: 8, debian: 9,
rubygems: 10 } rubygems: 10 }
enum status: { default: 0, hidden: 1, processing: 2 } enum status: { default: 0, hidden: 1, processing: 2, error: 3 }
scope :with_name, ->(name) { where(name: name) } scope :with_name, ->(name) { where(name: name) }
scope :with_name_like, ->(name) { where(arel_table[:name].matches(name)) } scope :with_name_like, ->(name) { where(arel_table[:name].matches(name)) }
...@@ -80,7 +82,7 @@ class Packages::Package < ApplicationRecord ...@@ -80,7 +82,7 @@ class Packages::Package < ApplicationRecord
scope :without_version_like, -> (version) { where.not(arel_table[:version].matches(version)) } scope :without_version_like, -> (version) { where.not(arel_table[:version].matches(version)) }
scope :with_package_type, ->(package_type) { where(package_type: package_type) } scope :with_package_type, ->(package_type) { where(package_type: package_type) }
scope :with_status, ->(status) { where(status: status) } scope :with_status, ->(status) { where(status: status) }
scope :displayable, -> { with_status(:default) } scope :displayable, -> { with_status(DISPLAYABLE_STATUSES) }
scope :including_build_info, -> { includes(pipelines: :user) } scope :including_build_info, -> { includes(pipelines: :user) }
scope :including_project_route, -> { includes(project: { namespace: :route }) } scope :including_project_route, -> { includes(project: { namespace: :route }) }
scope :including_tags, -> { includes(:tags) } scope :including_tags, -> { includes(:tags) }
......
...@@ -16,6 +16,10 @@ FactoryBot.define do ...@@ -16,6 +16,10 @@ FactoryBot.define do
status { :processing } status { :processing }
end end
trait :error do
status { :error }
end
factory :maven_package do factory :maven_package do
maven_metadatum maven_metadatum
......
...@@ -621,10 +621,12 @@ RSpec.describe Packages::Package, type: :model do ...@@ -621,10 +621,12 @@ RSpec.describe Packages::Package, type: :model do
describe '.displayable' do describe '.displayable' do
let_it_be(:hidden_package) { create(:maven_package, :hidden) } let_it_be(:hidden_package) { create(:maven_package, :hidden) }
let_it_be(:processing_package) { create(:maven_package, :processing) } let_it_be(:processing_package) { create(:maven_package, :processing) }
let_it_be(:error_package) { create(:maven_package, :error) }
subject { described_class.displayable } subject { described_class.displayable }
it 'does not include hidden packages', :aggregate_failures do it 'does not include non-displayable packages', :aggregate_failures do
is_expected.to include(error_package)
is_expected.not_to include(hidden_package) is_expected.not_to include(hidden_package)
is_expected.not_to include(processing_package) is_expected.not_to include(processing_package)
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