summaryrefslogtreecommitdiff
path: root/spec/migrations/insert_daily_invites_plan_limits_spec.rb
blob: 3265efcb0ce1739e2c19de0c8f02418b760b6f2e (plain)
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
# frozen_string_literal: true

require 'spec_helper'
require Rails.root.join('db', 'migrate', '20201007033723_insert_daily_invites_plan_limits.rb')

RSpec.describe InsertDailyInvitesPlanLimits do
  let(:plans) { table(:plans) }
  let(:plan_limits) { table(:plan_limits) }
  let!(:free_plan) { plans.create!(name: 'free') }
  let!(:bronze_plan) { plans.create!(name: 'bronze') }
  let!(:silver_plan) { plans.create!(name: 'silver') }
  let!(:gold_plan) { plans.create!(name: 'gold') }

  context 'when on Gitlab.com' do
    before do
      expect(Gitlab).to receive(:com?).at_most(:twice).and_return(true)
    end

    it 'correctly migrates up and down' do
      reversible_migration do |migration|
        migration.before -> {
          expect(plan_limits.where.not(daily_invites: 0)).to be_empty
        }

        # Expectations will run after the up migration.
        migration.after -> {
          expect(plan_limits.pluck(:plan_id, :daily_invites)).to contain_exactly(
            [free_plan.id, 20],
            [bronze_plan.id, 0],
            [silver_plan.id, 0],
            [gold_plan.id, 0]
          )
        }
      end
    end
  end

  context 'when on self hosted' do
    before do
      expect(Gitlab).to receive(:com?).at_most(:twice).and_return(false)
    end

    it 'correctly migrates up and down' do
      reversible_migration do |migration|
        migration.before -> {
          expect(plan_limits.pluck(:daily_invites)).to eq []
        }

        migration.after -> {
          expect(plan_limits.pluck(:daily_invites)).to eq []
        }
      end
    end
  end
end