diff options
Diffstat (limited to 'spec/models/packages/nuget')
-rw-r--r-- | spec/models/packages/nuget/metadatum_spec.rb | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/spec/models/packages/nuget/metadatum_spec.rb b/spec/models/packages/nuget/metadatum_spec.rb index 4b02353d6e8..e1520c0782f 100644 --- a/spec/models/packages/nuget/metadatum_spec.rb +++ b/spec/models/packages/nuget/metadatum_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe Packages::Nuget::Metadatum, type: :model, feature_category: :package_registry do + it { is_expected.to be_a Packages::Nuget::VersionNormalizable } + describe 'relationships' do it { is_expected.to belong_to(:package).inverse_of(:nuget_metadatum) } end @@ -15,6 +17,18 @@ RSpec.describe Packages::Nuget::Metadatum, type: :model, feature_category: :pack it { is_expected.to validate_presence_of(:description) } it { is_expected.to validate_length_of(:description).is_at_most(described_class::MAX_DESCRIPTION_LENGTH) } + context 'for normalized_version presence' do + it { is_expected.to validate_presence_of(:normalized_version) } + + context 'when nuget_normalized_version feature flag is disabled' do + before do + stub_feature_flags(nuget_normalized_version: false) + end + + it { is_expected.not_to validate_presence_of(:normalized_version) } + end + end + %i[license_url project_url icon_url].each do |url| describe "##{url}" do it { is_expected.to allow_value('http://sandbox.com').for(url) } @@ -36,4 +50,54 @@ RSpec.describe Packages::Nuget::Metadatum, type: :model, feature_category: :pack end end end + + it { is_expected.to delegate_method(:version).to(:package).with_prefix } + + describe '.normalized_version_in' do + let_it_be(:nuget_metadatums) { create_list(:nuget_metadatum, 2) } + + subject { described_class.normalized_version_in(nuget_metadatums.first.normalized_version) } + + it { is_expected.to contain_exactly(nuget_metadatums.first) } + end + + describe 'callbacks' do + describe '#set_normalized_version' do + using RSpec::Parameterized::TableSyntax + + let_it_be_with_reload(:nuget_metadatum) { create(:nuget_metadatum) } + + where(:version, :normalized_version) do + '1.0' | '1.0.0' + '1.0.0.0' | '1.0.0' + '0.1' | '0.1.0' + '1.0.7+r3456' | '1.0.7' + '8.0.0.00+RC.54' | '8.0.0' + '1.0.0-Alpha' | '1.0.0-alpha' + '1.0.00-RC-02' | '1.0.0-rc-02' + '8.0.000-preview.0.546.0' | '8.0.0-preview.0.546.0' + '0.1.0-dev.37+0999370' | '0.1.0-dev.37' + '1.2.3' | '1.2.3' + end + + with_them do + it 'saves the normalized version' do + nuget_metadatum.package.update_column(:version, version) + nuget_metadatum.save! + + expect(nuget_metadatum.normalized_version).to eq(normalized_version) + end + + context 'when the nuget_normalized_version feature flag is disabled' do + before do + stub_feature_flags(nuget_normalized_version: false) + end + + it 'does not save the normalized version' do + expect(nuget_metadatum.normalized_version).not_to eq(normalized_version) + end + end + end + end + end end |