diff options
Diffstat (limited to 'spec/models/packages')
-rw-r--r-- | spec/models/packages/package_spec.rb | 13 | ||||
-rw-r--r-- | spec/models/packages/rpm/metadatum_spec.rb | 36 |
2 files changed, 49 insertions, 0 deletions
diff --git a/spec/models/packages/package_spec.rb b/spec/models/packages/package_spec.rb index 526c57d08b0..fb88dbb4212 100644 --- a/spec/models/packages/package_spec.rb +++ b/spec/models/packages/package_spec.rb @@ -21,6 +21,7 @@ RSpec.describe Packages::Package, type: :model do it { is_expected.to have_one(:nuget_metadatum).inverse_of(:package) } it { is_expected.to have_one(:rubygems_metadatum).inverse_of(:package) } it { is_expected.to have_one(:npm_metadatum).inverse_of(:package) } + it { is_expected.to have_one(:rpm_metadatum).inverse_of(:package) } end describe '.with_debian_codename' do @@ -1356,4 +1357,16 @@ RSpec.describe Packages::Package, type: :model do it { is_expected.to eq(normalized_name) } end end + + describe '#touch_last_downloaded_at' do + let_it_be(:package) { create(:package) } + + subject { package.touch_last_downloaded_at } + + it 'updates the downloaded_at' do + expect(::Gitlab::Database::LoadBalancing::Session).to receive(:without_sticky_writes).and_call_original + expect { subject } + .to change(package, :last_downloaded_at).from(nil).to(instance_of(ActiveSupport::TimeWithZone)) + end + end end diff --git a/spec/models/packages/rpm/metadatum_spec.rb b/spec/models/packages/rpm/metadatum_spec.rb new file mode 100644 index 00000000000..0e7817fdf86 --- /dev/null +++ b/spec/models/packages/rpm/metadatum_spec.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true +require 'spec_helper' + +RSpec.describe Packages::Rpm::Metadatum, type: :model do + describe 'relationships' do + it { is_expected.to belong_to(:package) } + end + + describe 'validations' do + it { is_expected.to validate_presence_of(:package) } + it { is_expected.to validate_presence_of(:epoch) } + it { is_expected.to validate_presence_of(:release) } + it { is_expected.to validate_presence_of(:summary) } + it { is_expected.to validate_presence_of(:description) } + it { is_expected.to validate_presence_of(:arch) } + + it { is_expected.to validate_numericality_of(:epoch).only_integer.is_greater_than_or_equal_to(0) } + + it { is_expected.to validate_length_of(:release).is_at_most(128) } + it { is_expected.to validate_length_of(:summary).is_at_most(1000) } + it { is_expected.to validate_length_of(:description).is_at_most(5000) } + it { is_expected.to validate_length_of(:arch).is_at_most(255) } + it { is_expected.to validate_length_of(:license).is_at_most(1000) } + it { is_expected.to validate_length_of(:url).is_at_most(1000) } + + describe '#rpm_package_type' do + it 'will not allow a package with a different package_type' do + package = build('conan_package') + rpm_metadatum = build('rpm_metadatum', package: package) + + expect(rpm_metadatum).not_to be_valid + expect(rpm_metadatum.errors.to_a).to include('Package type must be RPM') + end + end + end +end |