diff options
Diffstat (limited to 'spec/models/packages/debian/publication_spec.rb')
-rw-r--r-- | spec/models/packages/debian/publication_spec.rb | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/spec/models/packages/debian/publication_spec.rb b/spec/models/packages/debian/publication_spec.rb new file mode 100644 index 00000000000..0ed056f499b --- /dev/null +++ b/spec/models/packages/debian/publication_spec.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true +require 'spec_helper' + +RSpec.describe Packages::Debian::Publication, type: :model do + let_it_be_with_reload(:publication) { create(:debian_publication) } + + subject { publication } + + describe 'relationships' do + it { is_expected.to belong_to(:package).inverse_of(:debian_publication).class_name('Packages::Package') } + it { is_expected.to belong_to(:distribution).inverse_of(:publications).class_name('Packages::Debian::ProjectDistribution').with_foreign_key(:distribution_id) } + end + + describe 'validations' do + describe '#package' do + it { is_expected.to validate_presence_of(:package) } + end + + describe '#valid_debian_package_type' do + context 'with package type not being Debian' do + before do + publication.package.package_type = 'generic' + end + + it 'will not allow package type not being Debian' do + expect(publication).not_to be_valid + expect(publication.errors.to_a).to eq(['Package type must be Debian']) + end + end + + context 'with package not being a Debian package' do + before do + publication.package.version = nil + end + + it 'will not allow package not being a distribution' do + expect(publication).not_to be_valid + expect(publication.errors.to_a).to eq(['Package must be a Debian package']) + end + end + end + + describe '#distribution' do + it { is_expected.to validate_presence_of(:distribution) } + end + end +end |