summaryrefslogtreecommitdiff
path: root/spec/models/packages/debian/publication_spec.rb
blob: 0ed056f499bfd53b8e27fc203be5dd05bf9a2a27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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