File: project_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 (110 lines) | stat: -rw-r--r-- 3,019 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# frozen_string_literal: true

RSpec.shared_examples 'returns true if project is inactive' do
  using RSpec::Parameterized::TableSyntax

  where(:storage_size, :last_activity_at, :expected_result) do
    1.megabyte  | 1.month.ago | false
    1.megabyte  | 3.years.ago | false
    8.megabytes | 1.month.ago | false
    8.megabytes | 3.years.ago | true
  end

  with_them do
    before do
      stub_application_setting(inactive_projects_min_size_mb: 5)
      stub_application_setting(inactive_projects_send_warning_email_after_months: 24)

      project.statistics.storage_size = storage_size
      project.last_activity_at = last_activity_at
      project.save!
    end

    it 'returns expected result' do
      expect(project.inactive?).to eq(expected_result)
    end
  end
end

RSpec.shared_examples 'checks parent group feature flag' do
  let(:group) { subject_project.group }
  let(:root_group) { group.parent }

  subject { subject_project.public_send(feature_flag_method) }

  context 'when feature flag is disabled globally' do
    before do
      stub_feature_flags(feature_flag => false)
    end

    it { is_expected.to be_falsey }
  end

  context 'when feature flag is enabled globally' do
    it { is_expected.to be_truthy }
  end

  context 'when feature flag is enabled for the root group' do
    before do
      stub_feature_flags(feature_flag => root_group)
    end

    it { is_expected.to be_truthy }
  end

  context 'when feature flag is enabled for the group' do
    before do
      stub_feature_flags(feature_flag => group)
    end

    it { is_expected.to be_truthy }
  end
end

RSpec.shared_examples 'checks parent group and self feature flag' do
  it_behaves_like 'checks parent group feature flag'

  context 'when feature flag is enabled for the project' do
    before do
      stub_feature_flags(feature_flag => subject_project)
    end

    context 'when project belongs to a group' do
      let(:subject_project) { group_project }

      it { is_expected.to be_truthy }
    end

    context 'when project does not belong to a group' do
      let(:subject_project) do
        create(:project, namespace: create(:namespace))
      end

      it { is_expected.to be_truthy }
    end
  end
end

RSpec.shared_examples 'refreshes project.lfs_file_locks_changed_epoch value' do
  it 'updates the lfs_file_locks_changed_epoch value', :clean_gitlab_redis_cache do
    travel_to(1.hour.ago) { project.refresh_lfs_file_locks_changed_epoch }

    original_epoch = project.lfs_file_locks_changed_epoch

    subject

    expect(project.lfs_file_locks_changed_epoch).to be > original_epoch
  end
end

RSpec.shared_examples 'does not refresh project.lfs_file_locks_changed_epoch' do
  it 'does not update the lfs_file_locks_changed_epoch value', :clean_gitlab_redis_cache do
    travel_to(1.hour.ago) { project.refresh_lfs_file_locks_changed_epoch }

    original_epoch = project.lfs_file_locks_changed_epoch

    subject

    expect(project.lfs_file_locks_changed_epoch).to eq original_epoch
  end
end