diff options
Diffstat (limited to 'spec/models/packages/package_spec.rb')
-rw-r--r-- | spec/models/packages/package_spec.rb | 82 |
1 files changed, 81 insertions, 1 deletions
diff --git a/spec/models/packages/package_spec.rb b/spec/models/packages/package_spec.rb index 52ef61e3d44..1e44327c089 100644 --- a/spec/models/packages/package_spec.rb +++ b/spec/models/packages/package_spec.rb @@ -404,7 +404,8 @@ RSpec.describe Packages::Package, type: :model do it { is_expected.not_to allow_value(nil).for(:version) } it { is_expected.not_to allow_value('').for(:version) } it { is_expected.to allow_value('v1.2.3').for(:version) } - it { is_expected.not_to allow_value('1.2.3').for(:version) } + it { is_expected.to allow_value('1.2.3').for(:version) } + it { is_expected.not_to allow_value('v1.2').for(:version) } end it_behaves_like 'validating version to be SemVer compliant for', :npm_package @@ -729,6 +730,38 @@ RSpec.describe Packages::Package, type: :model do end end + context 'sorting' do + let_it_be(:project) { create(:project, name: 'aaa' ) } + let_it_be(:project2) { create(:project, name: 'bbb' ) } + let_it_be(:package1) { create(:package, project: project ) } + let_it_be(:package2) { create(:package, project: project2 ) } + let_it_be(:package3) { create(:package, project: project2 ) } + let_it_be(:package4) { create(:package, project: project ) } + + it 'orders packages by their projects name ascending' do + expect(Packages::Package.order_project_name).to eq([package1, package4, package2, package3]) + end + + it 'orders packages by their projects name descending' do + expect(Packages::Package.order_project_name_desc).to eq([package2, package3, package1, package4]) + end + + shared_examples 'order_project_path scope' do + it 'orders packages by their projects path asc, then package id asc' do + expect(Packages::Package.order_project_path).to eq([package1, package4, package2, package3]) + end + end + + shared_examples 'order_project_path_desc scope' do + it 'orders packages by their projects path desc, then package id desc' do + expect(Packages::Package.order_project_path_desc).to eq([package3, package2, package4, package1]) + end + end + + it_behaves_like 'order_project_path scope' + it_behaves_like 'order_project_path_desc scope' + end + describe '.order_by_package_file' do let_it_be(:project) { create(:project) } let_it_be(:package1) { create(:maven_package, project: project) } @@ -743,6 +776,33 @@ RSpec.describe Packages::Package, type: :model do end end + describe '.keyset_pagination_order' do + let(:join_class) { nil } + let(:column_name) { nil } + let(:direction) { nil } + + subject { described_class.keyset_pagination_order(join_class: join_class, column_name: column_name, direction: direction) } + + it { expect { subject }.to raise_error(NoMethodError) } + + context 'with valid params' do + let(:join_class) { Project } + let(:column_name) { :name } + + context 'ascending direction' do + let(:direction) { :asc } + + it { is_expected.to eq('projects.name asc NULLS LAST, "packages_packages"."id" ASC') } + end + + context 'descending direction' do + let(:direction) { :desc } + + it { is_expected.to eq('projects.name desc NULLS FIRST, "packages_packages"."id" DESC') } + end + end + end + describe '#versions' do let_it_be(:project) { create(:project) } let_it_be(:package) { create(:maven_package, project: project) } @@ -838,6 +898,26 @@ RSpec.describe Packages::Package, type: :model do end end + describe '#infrastructure_package?' do + let(:package) { create(:package) } + + subject { package.infrastructure_package? } + + it { is_expected.to eq(false) } + + context 'with generic package' do + let(:package) { create(:generic_package) } + + it { is_expected.to eq(false) } + end + + context 'with terraform module package' do + let(:package) { create(:terraform_module_package) } + + it { is_expected.to eq(true) } + end + end + describe 'plan_limits' do Packages::Package.package_types.keys.without('composer').each do |pt| plan_limit_name = if pt == 'generic' |