File: container_expiration_policy_shared_examples.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (40 lines) | stat: -rw-r--r-- 1,630 bytes parent folder | download
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
# frozen_string_literal: true

RSpec.shared_examples 'updating the container expiration policy attributes' do |mode:, to:, from: {}|
  if mode == :create
    it 'creates a new container expiration policy' do
      expect { subject }
        .to change { project.reload.container_expiration_policy.present? }.from(false).to(true)
        .and change { ContainerExpirationPolicy.count }.by(1)
    end
  else
    it_behaves_like 'not creating the container expiration policy'
  end

  it 'updates the container expiration policy' do
    if from.empty?
      subject

      expect(container_expiration_policy.reload.cadence).to eq(to[:cadence])
      expect(container_expiration_policy.keep_n).to eq(to[:keep_n])
      expect(container_expiration_policy.older_than).to eq(to[:older_than])
    else
      expect { subject }
        .to change { container_expiration_policy.reload.cadence }.from(from[:cadence]).to(to[:cadence])
        .and change { container_expiration_policy.reload.keep_n }.from(from[:keep_n]).to(to[:keep_n])
        .and change { container_expiration_policy.reload.older_than }.from(from[:older_than]).to(to[:older_than])
    end
  end
end

RSpec.shared_examples 'not creating the container expiration policy' do
  it "doesn't create the container expiration policy" do
    expect { subject }.not_to change { ContainerExpirationPolicy.count }
  end
end

RSpec.shared_examples 'creating the container expiration policy' do
  it_behaves_like 'updating the container expiration policy attributes', mode: :create, to: { cadence: '3month', keep_n: 100, older_than: '14d' }

  it_behaves_like 'returning a success'
end