debian-mirror-gitlab/spec/models/packages/cleanup/policy_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

66 lines
2.2 KiB
Ruby
Raw Permalink Normal View History

2022-07-16 23:28:13 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Packages::Cleanup::Policy, type: :model do
describe 'relationships' do
it { is_expected.to belong_to(:project) }
end
describe 'validations' do
it { is_expected.to validate_presence_of(:project) }
2022-08-27 11:52:29 +05:30
2022-07-16 23:28:13 +05:30
it do
is_expected
.to validate_inclusion_of(:keep_n_duplicated_package_files)
.in_array(described_class::KEEP_N_DUPLICATED_PACKAGE_FILES_VALUES)
2022-07-23 23:45:48 +05:30
.with_message('is invalid')
2022-07-16 23:28:13 +05:30
end
end
describe '.active' do
let_it_be(:active_policy) { create(:packages_cleanup_policy) }
let_it_be(:inactive_policy) { create(:packages_cleanup_policy, keep_n_duplicated_package_files: 'all') }
subject { described_class.active }
it { is_expected.to contain_exactly(active_policy) }
end
2022-08-13 15:12:31 +05:30
describe '.with_packages' do
let_it_be(:policy_with_packages) { create(:packages_cleanup_policy) }
let_it_be(:policy_without_packages) { create(:packages_cleanup_policy) }
let_it_be(:package) { create(:package, project: policy_with_packages.project) }
subject { described_class.with_packages }
it { is_expected.to contain_exactly(policy_with_packages) }
end
describe '.runnable' do
let_it_be(:runnable_policy_with_packages) { create(:packages_cleanup_policy, :runnable) }
let_it_be(:runnable_policy_without_packages) { create(:packages_cleanup_policy, :runnable) }
let_it_be(:non_runnable_policy_with_packages) { create(:packages_cleanup_policy) }
let_it_be(:non_runnable_policy_without_packages) { create(:packages_cleanup_policy) }
let_it_be(:package1) { create(:package, project: runnable_policy_with_packages.project) }
let_it_be(:package2) { create(:package, project: non_runnable_policy_with_packages.project) }
subject { described_class.runnable }
it { is_expected.to contain_exactly(runnable_policy_with_packages) }
end
describe '#keep_n_duplicated_package_files_disabled?' do
subject { policy.keep_n_duplicated_package_files_disabled? }
%w[all 1].each do |value|
context "with value set to #{value}" do
let(:policy) { build(:packages_cleanup_policy, keep_n_duplicated_package_files: value) }
it { is_expected.to eq(value == 'all') }
end
end
end
2022-07-16 23:28:13 +05:30
end