File: feature_gate_spec.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 (47 lines) | stat: -rw-r--r-- 1,456 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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe FeatureGate do
  describe '.actor_from_id' do
    using RSpec::Parameterized::TableSyntax

    subject(:actor_from_id) { model_class.actor_from_id(model_id) }

    where(:model_class, :model_id, :expected) do
      Project                      | 1 | 'Project:1'
      Group                        | 2 | 'Group:2'
      User                         | 3 | 'User:3'
      Ci::Runner                   | 4 | 'Ci::Runner:4'
      Namespace                    | 5 | 'Namespace:5'
      Namespaces::ProjectNamespace | 6 | 'Namespaces::ProjectNamespace:6'
      Namespaces::UserNamespace    | 7 | 'Namespaces::UserNamespace:7'
    end

    with_them do
      it 'returns an object that has the correct flipper_id' do
        expect(actor_from_id).to have_attributes(flipper_id: expected)
      end
    end
  end

  describe '#flipper_id' do
    where(:factory) { %i[project group user ci_runner namespace] }

    with_them do
      it 'returns nil when object is not persisted' do
        actor = build(factory)

        expect(actor.flipper_id).to be_nil
      end

      it 'returns flipper_id when object is persisted' do
        # rubocop:disable Rails/SaveBang -- This is FactoryBot#create, not ActiveModel#create.
        actor = create(factory)
        # rubocop:enable Rails/SaveBang

        expect(actor.flipper_id).to eq("#{actor.class.name}:#{actor.id}")
      end
    end
  end
end