summaryrefslogtreecommitdiff
path: root/spec/models/packages
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-09-19 01:45:44 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-09-19 01:45:44 +0000
commit85dc423f7090da0a52c73eb66faf22ddb20efff9 (patch)
tree9160f299afd8c80c038f08e1545be119f5e3f1e1 /spec/models/packages
parent15c2c8c66dbe422588e5411eee7e68f1fa440bb8 (diff)
downloadgitlab-ce-85dc423f7090da0a52c73eb66faf22ddb20efff9.tar.gz
Add latest changes from gitlab-org/gitlab@13-4-stable-ee
Diffstat (limited to 'spec/models/packages')
-rw-r--r--spec/models/packages/package_file_spec.rb6
-rw-r--r--spec/models/packages/package_spec.rb118
2 files changed, 116 insertions, 8 deletions
diff --git a/spec/models/packages/package_file_spec.rb b/spec/models/packages/package_file_spec.rb
index 7cc8e13d449..6b992dbc2a5 100644
--- a/spec/models/packages/package_file_spec.rb
+++ b/spec/models/packages/package_file_spec.rb
@@ -33,15 +33,17 @@ RSpec.describe Packages::PackageFile, type: :model do
end
context 'updating project statistics' do
+ let_it_be(:package, reload: true) { create(:package) }
+
context 'when the package file has an explicit size' do
it_behaves_like 'UpdateProjectStatistics' do
- subject { build(:package_file, :jar, size: 42) }
+ subject { build(:package_file, :jar, package: package, size: 42) }
end
end
context 'when the package file does not have a size' do
it_behaves_like 'UpdateProjectStatistics' do
- subject { build(:package_file, size: nil) }
+ subject { build(:package_file, package: package, size: nil) }
end
end
end
diff --git a/spec/models/packages/package_spec.rb b/spec/models/packages/package_spec.rb
index 4170bf595f0..ea1f75d04e7 100644
--- a/spec/models/packages/package_spec.rb
+++ b/spec/models/packages/package_spec.rb
@@ -6,6 +6,7 @@ RSpec.describe Packages::Package, type: :model do
describe 'relationships' do
it { is_expected.to belong_to(:project) }
+ it { is_expected.to belong_to(:creator) }
it { is_expected.to have_many(:package_files).dependent(:destroy) }
it { is_expected.to have_many(:dependency_links).inverse_of(:package) }
it { is_expected.to have_many(:tags).inverse_of(:package) }
@@ -84,7 +85,7 @@ RSpec.describe Packages::Package, type: :model do
end
describe 'validations' do
- subject { create(:package) }
+ subject { build(:package) }
it { is_expected.to validate_presence_of(:project) }
it { is_expected.to validate_uniqueness_of(:name).scoped_to(:project_id, :version, :package_type) }
@@ -95,7 +96,7 @@ RSpec.describe Packages::Package, type: :model do
it { is_expected.not_to allow_value("my(dom$$$ain)com.my-app").for(:name) }
context 'conan package' do
- subject { create(:conan_package) }
+ subject { build_stubbed(:conan_package) }
let(:fifty_one_characters) {'f_b' * 17}
@@ -112,7 +113,7 @@ RSpec.describe Packages::Package, type: :model do
describe '#version' do
RSpec.shared_examples 'validating version to be SemVer compliant for' do |factory_name|
context "for #{factory_name}" do
- subject { create(factory_name) }
+ subject { build_stubbed(factory_name) }
it { is_expected.to allow_value('1.2.3').for(:version) }
it { is_expected.to allow_value('1.2.3-beta').for(:version) }
@@ -126,7 +127,7 @@ RSpec.describe Packages::Package, type: :model do
end
context 'conan package' do
- subject { create(:conan_package) }
+ subject { build_stubbed(:conan_package) }
let(:fifty_one_characters) {'1.2' * 17}
@@ -142,7 +143,7 @@ RSpec.describe Packages::Package, type: :model do
end
context 'maven package' do
- subject { create(:maven_package) }
+ subject { build_stubbed(:maven_package) }
it { is_expected.to allow_value('0').for(:version) }
it { is_expected.to allow_value('1').for(:version) }
@@ -169,6 +170,92 @@ RSpec.describe Packages::Package, type: :model do
it { is_expected.not_to allow_value('%2e%2e%2f1.2.3').for(:version) }
end
+ context 'pypi package' do
+ subject { create(:pypi_package) }
+
+ it { is_expected.to allow_value('0.1').for(:version) }
+ it { is_expected.to allow_value('2.0').for(:version) }
+ it { is_expected.to allow_value('1.2.0').for(:version) }
+ it { is_expected.to allow_value('0100!0.0').for(:version) }
+ it { is_expected.to allow_value('00!1.2').for(:version) }
+ it { is_expected.to allow_value('1.0a').for(:version) }
+ it { is_expected.to allow_value('1.0-a').for(:version) }
+ it { is_expected.to allow_value('1.0.a1').for(:version) }
+ it { is_expected.to allow_value('1.0a1').for(:version) }
+ it { is_expected.to allow_value('1.0-a1').for(:version) }
+ it { is_expected.to allow_value('1.0alpha1').for(:version) }
+ it { is_expected.to allow_value('1.0b1').for(:version) }
+ it { is_expected.to allow_value('1.0beta1').for(:version) }
+ it { is_expected.to allow_value('1.0rc1').for(:version) }
+ it { is_expected.to allow_value('1.0pre1').for(:version) }
+ it { is_expected.to allow_value('1.0preview1').for(:version) }
+ it { is_expected.to allow_value('1.0.dev1').for(:version) }
+ it { is_expected.to allow_value('1.0.DEV1').for(:version) }
+ it { is_expected.to allow_value('1.0.post1').for(:version) }
+ it { is_expected.to allow_value('1.0.rev1').for(:version) }
+ it { is_expected.to allow_value('1.0.r1').for(:version) }
+ it { is_expected.to allow_value('1.0c2').for(:version) }
+ it { is_expected.to allow_value('2012.15').for(:version) }
+ it { is_expected.to allow_value('1.0+5').for(:version) }
+ it { is_expected.to allow_value('1.0+abc.5').for(:version) }
+ it { is_expected.to allow_value('1!1.1').for(:version) }
+ it { is_expected.to allow_value('1.0c3').for(:version) }
+ it { is_expected.to allow_value('1.0rc2').for(:version) }
+ it { is_expected.to allow_value('1.0c1').for(:version) }
+ it { is_expected.to allow_value('1.0b2-346').for(:version) }
+ it { is_expected.to allow_value('1.0b2.post345').for(:version) }
+ it { is_expected.to allow_value('1.0b2.post345.dev456').for(:version) }
+ it { is_expected.to allow_value('1.2.rev33+123456').for(:version) }
+ it { is_expected.to allow_value('1.1.dev1').for(:version) }
+ it { is_expected.to allow_value('1.0b1.dev456').for(:version) }
+ it { is_expected.to allow_value('1.0a12.dev456').for(:version) }
+ it { is_expected.to allow_value('1.0b2').for(:version) }
+ it { is_expected.to allow_value('1.0.dev456').for(:version) }
+ it { is_expected.to allow_value('1.0c1.dev456').for(:version) }
+ it { is_expected.to allow_value('1.0.post456').for(:version) }
+ it { is_expected.to allow_value('1.0.post456.dev34').for(:version) }
+ it { is_expected.to allow_value('1.2+123abc').for(:version) }
+ it { is_expected.to allow_value('1.2+abc').for(:version) }
+ it { is_expected.to allow_value('1.2+abc123').for(:version) }
+ it { is_expected.to allow_value('1.2+abc123def').for(:version) }
+ it { is_expected.to allow_value('1.2+1234.abc').for(:version) }
+ it { is_expected.to allow_value('1.2+123456').for(:version) }
+ it { is_expected.to allow_value('1.2.r32+123456').for(:version) }
+ it { is_expected.to allow_value('1!1.2.rev33+123456').for(:version) }
+ it { is_expected.to allow_value('1.0a12').for(:version) }
+ it { is_expected.to allow_value('1.2.3-45+abcdefgh').for(:version) }
+ it { is_expected.to allow_value('v1.2.3').for(:version) }
+ it { is_expected.not_to allow_value('1.2.3-45-abcdefgh').for(:version) }
+ it { is_expected.not_to allow_value('..1.2.3').for(:version) }
+ it { is_expected.not_to allow_value(' 1.2.3').for(:version) }
+ it { is_expected.not_to allow_value("1.2.3 \r\t").for(:version) }
+ it { is_expected.not_to allow_value("\r\t 1.2.3").for(:version) }
+ it { is_expected.not_to allow_value('1./2.3').for(:version) }
+ it { is_expected.not_to allow_value('1.2.3-4/../../').for(:version) }
+ it { is_expected.not_to allow_value('1.2.3-4%2e%2e%').for(:version) }
+ it { is_expected.not_to allow_value('../../../../../1.2.3').for(:version) }
+ it { is_expected.not_to allow_value('%2e%2e%2f1.2.3').for(:version) }
+ end
+
+ context 'generic package' do
+ subject { build_stubbed(:generic_package) }
+
+ it { is_expected.to validate_presence_of(:version) }
+ it { is_expected.to allow_value('1.2.3').for(:version) }
+ it { is_expected.to allow_value('1.3.350').for(:version) }
+ it { is_expected.not_to allow_value('1.3.350-20201230123456').for(:version) }
+ it { is_expected.not_to allow_value('..1.2.3').for(:version) }
+ it { is_expected.not_to allow_value(' 1.2.3').for(:version) }
+ it { is_expected.not_to allow_value("1.2.3 \r\t").for(:version) }
+ it { is_expected.not_to allow_value("\r\t 1.2.3").for(:version) }
+ it { is_expected.not_to allow_value('1.2.3-4/../../').for(:version) }
+ it { is_expected.not_to allow_value('1.2.3-4%2e%2e%').for(:version) }
+ it { is_expected.not_to allow_value('../../../../../1.2.3').for(:version) }
+ it { is_expected.not_to allow_value('%2e%2e%2f1.2.3').for(:version) }
+ it { is_expected.not_to allow_value('').for(:version) }
+ it { is_expected.not_to allow_value(nil).for(:version) }
+ end
+
it_behaves_like 'validating version to be SemVer compliant for', :npm_package
it_behaves_like 'validating version to be SemVer compliant for', :nuget_package
end
@@ -178,7 +265,7 @@ RSpec.describe Packages::Package, type: :model do
let!(:package) { create(:npm_package) }
it 'will not allow a package of the same name' do
- new_package = build(:npm_package, name: package.name)
+ new_package = build(:npm_package, project: create(:project), name: package.name)
expect(new_package).not_to be_valid
end
@@ -482,4 +569,23 @@ RSpec.describe Packages::Package, type: :model do
it { is_expected.to contain_exactly(*tags) }
end
end
+
+ describe 'plan_limits' do
+ Packages::Package.package_types.keys.without('composer').each do |pt|
+ plan_limit_name = if pt == 'generic'
+ "#{pt}_packages_max_file_size"
+ else
+ "#{pt}_max_file_size"
+ end
+
+ context "File size limits for #{pt}" do
+ let(:package) { create("#{pt}_package") }
+
+ it "plan_limits includes column #{plan_limit_name}" do
+ expect { package.project.actual_limits.send(plan_limit_name) }
+ .not_to raise_error(NoMethodError)
+ end
+ end
+ end
+ end
end