summaryrefslogtreecommitdiff
path: root/spec/models/packages/nuget/metadatum_spec.rb
blob: c1bc5429500a7c1c64e14d1c6d51527609c7ffc1 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Packages::Nuget::Metadatum, type: :model do
  describe 'relationships' do
    it { is_expected.to belong_to(:package).inverse_of(:nuget_metadatum) }
  end

  describe 'validations' do
    it { is_expected.to validate_presence_of(:package) }

    %i[license_url project_url icon_url].each do |url|
      describe "##{url}" do
        it { is_expected.to allow_value('http://sandbox.com').for(url) }
        it { is_expected.to allow_value('https://sandbox.com').for(url) }
        it { is_expected.not_to allow_value('123').for(url) }
        it { is_expected.not_to allow_value('sandbox.com').for(url) }
      end

      describe '#ensure_at_least_one_field_supplied' do
        subject { build(:nuget_metadatum) }

        it 'rejects unfilled metadatum' do
          subject.attributes = { license_url: nil, project_url: nil, icon_url: nil }

          expect(subject).not_to be_valid
          expect(subject.errors).to contain_exactly('Nuget metadatum must have at least license_url, project_url or icon_url set')
        end
      end

      describe '#ensure_nuget_package_type' do
        subject { build(:nuget_metadatum) }

        it 'rejects if not linked to a nuget package' do
          subject.package = build(:npm_package)

          expect(subject).not_to be_valid
          expect(subject.errors).to contain_exactly('Package type must be NuGet')
        end
      end
    end
  end
end