alpha_beta_feature_support_shared_examples.rb 1.9 KB
Newer Older
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
# frozen_string_literal: true

# This needs an `entity` object: Project or Group.
RSpec.shared_examples 'an entity with alpha/beta feature support' do
  where(level: %w[alpha beta])

  with_them do
    let(:method_name) { "#{level}_feature_available?" }

    context 'when license does not allow it' do
      before do
        stub_licensed_features(insights: false)
      end

      context 'when the feature flag is disabled globally' do
        before do
          stub_feature_flags(insights: false)
        end

        it { expect(entity.public_send(method_name, :insights)).to be_falsy }
      end

      context 'when the feature flag is enabled globally' do
        before do
          stub_feature_flags(insights: true)
        end

        it { expect(entity.public_send(method_name, :insights)).to be_truthy }
      end

      context 'when the feature flag is enabled for the entity' do
        before do
          stub_feature_flags(insights: { enabled: true, thing: entity })
        end

        it { expect(entity.public_send(method_name, :insights)).to be_truthy }
      end
    end

    context 'when license allows it' do
      before do
        stub_licensed_features(insights: true)
      end

      context 'when the feature flag is disabled globally' do
        before do
          stub_feature_flags(insights: false)
        end

        it { expect(entity.public_send(method_name, :insights)).to be_falsy }
      end

      context 'when the feature flag is enabled globally' do
        before do
          stub_feature_flags(insights: true)
        end

        it { expect(entity.public_send(method_name, :insights)).to be_truthy }
      end

      context 'when the feature flag is enabled for the entity' do
        before do
          stub_feature_flags(insights: { enabled: true, thing: entity })
        end

        it { expect(entity.public_send(method_name, :insights)).to be_truthy }
      end
    end
  end
end