File: plan_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 (80 lines) | stat: -rw-r--r-- 2,142 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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Plan do
  describe 'scopes', :aggregate_failures do
    let_it_be(:default_plan) { create(:default_plan) }

    describe '.by_name' do
      it 'returns plans by their name' do
        expect(described_class.by_name('default')).to match_array([default_plan])
        expect(described_class.by_name(%w[default unknown])).to match_array([default_plan])
        expect(described_class.by_name(nil)).to be_empty
      end
    end
  end

  describe '#default?' do
    subject { plan.default? }

    Plan.default_plans.each do |plan|
      context "when '#{plan}'" do
        let(:plan) { build("#{plan}_plan".to_sym) }

        it { is_expected.to be_truthy }
      end
    end
  end

  describe '#default' do
    context 'when default plan exists' do
      let!(:default_plan) { create(:default_plan) }

      it 'returns default plan' do
        expect(described_class.default).to eq(default_plan)
      end
    end

    context 'when default plan does not exist' do
      it 'creates default plan' do
        expect { described_class.default }.to change { Plan.count }.by(1)
      end

      it 'creates plan with correct attributes' do
        plan = described_class.default

        expect(plan.name).to eq(Plan::DEFAULT)
        expect(plan.title).to eq(Plan::DEFAULT.titleize)
      end
    end
  end

  context 'when updating plan limits' do
    let(:plan) { described_class.default }

    it { expect(plan).to be_persisted }

    it { expect(plan.actual_limits).not_to be_persisted }

    it 'successfully updates the limits' do
      expect(plan.actual_limits.update!(ci_instance_level_variables: 100)).to be_truthy
    end
  end

  describe '#ids_for_names' do
    let_it_be(:default_plan) { create(:default_plan) }

    subject(:plan) { described_class.ids_for_names([default_plan.name]) }

    it { is_expected.to eq([default_plan.id]) }
  end

  describe '#names_for_ids' do
    let_it_be(:default_plan) { create(:default_plan) }

    subject(:plan) { described_class.names_for_ids([default_plan.id]) }

    it { is_expected.to eq([default_plan.name]) }
  end
end