diff options
Diffstat (limited to 'spec/models/packages/package_spec.rb')
-rw-r--r-- | spec/models/packages/package_spec.rb | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/spec/models/packages/package_spec.rb b/spec/models/packages/package_spec.rb index 41a731b87e9..705a1991845 100644 --- a/spec/models/packages/package_spec.rb +++ b/spec/models/packages/package_spec.rb @@ -10,6 +10,8 @@ RSpec.describe Packages::Package, type: :model do 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) } + it { is_expected.to have_many(:build_infos).inverse_of(:package) } + it { is_expected.to have_many(:pipelines).through(:build_infos) } it { is_expected.to have_one(:conan_metadatum).inverse_of(:package) } it { is_expected.to have_one(:maven_metadatum).inverse_of(:package) } it { is_expected.to have_one(:nuget_metadatum).inverse_of(:package) } @@ -171,6 +173,13 @@ RSpec.describe Packages::Package, type: :model do it { is_expected.not_to allow_value('%2e%2e%2f1.2.3').for(:version) } end + context 'composer package' do + it_behaves_like 'validating version to be SemVer compliant for', :composer_package + + it { is_expected.to allow_value('dev-master').for(:version) } + it { is_expected.to allow_value('2.x-dev').for(:version) } + end + context 'maven package' do subject { build_stubbed(:maven_package) } @@ -573,7 +582,7 @@ RSpec.describe Packages::Package, type: :model do end describe '#pipeline' do - let_it_be(:package) { create(:maven_package) } + let_it_be_with_refind(:package) { create(:maven_package) } context 'package without pipeline' do it 'returns nil if there is no pipeline' do @@ -585,7 +594,7 @@ RSpec.describe Packages::Package, type: :model do let_it_be(:pipeline) { create(:ci_pipeline) } before do - package.create_build_info!(pipeline: pipeline) + package.build_infos.create!(pipeline: pipeline) end it 'returns the pipeline' do @@ -630,4 +639,23 @@ RSpec.describe Packages::Package, type: :model do end end end + + describe '#original_build_info' do + let_it_be_with_refind(:package) { create(:npm_package) } + + context 'without build_infos' do + it 'returns nil' do + expect(package.original_build_info).to be_nil + end + end + + context 'with build_infos' do + let_it_be(:first_build_info) { create(:package_build_info, :with_pipeline, package: package) } + let_it_be(:second_build_info) { create(:package_build_info, :with_pipeline, package: package) } + + it 'returns the first build info' do + expect(package.original_build_info).to eq(first_build_info) + end + end + end end |