Welcome to mirror list, hosted at ThFree Co, Russian Federation.

insert_daily_invites_trial_plan_limits_spec.rb « migrations « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 412bb5917e31121f69b9512f73c14c3187a91bda (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
# frozen_string_literal: true

require 'spec_helper'
require_migration!

RSpec.describe InsertDailyInvitesTrialPlanLimits, feature_category: :groups_and_projects do
  let(:plans) { table(:plans) }
  let(:plan_limits) { table(:plan_limits) }
  let!(:premium_trial_plan) { plans.create!(name: 'premium_trial') }
  let!(:ultimate_trial_plan) { plans.create!(name: 'ultimate_trial') }

  context 'when on gitlab.com' do
    before do
      allow(Gitlab).to receive(:com?).and_return(true)
    end

    it 'correctly migrates up and down' do
      reversible_migration do |migration|
        migration.before -> {
          trial_plan_ids = [premium_trial_plan.id, ultimate_trial_plan.id]
          expect(plan_limits.where(plan_id: trial_plan_ids).where.not(daily_invites: 0)).to be_empty
        }

        migration.after -> {
          expect(plan_limits.pluck(:plan_id, :daily_invites))
            .to contain_exactly([premium_trial_plan.id, 50], [ultimate_trial_plan.id, 50])
        }
      end
    end
  end

  context 'when on self-managed' do
    before do
      allow(Gitlab).to receive(:com?).and_return(false)
    end

    it 'correctly migrates up and down' do
      reversible_migration do |migration|
        trial_plan_ids = [premium_trial_plan.id, ultimate_trial_plan.id]

        migration.before -> {
          expect(plan_limits.where(plan_id: trial_plan_ids).where.not(daily_invites: 0)).to be_empty
        }

        migration.after -> {
          expect(plan_limits.where(plan_id: trial_plan_ids).where.not(daily_invites: 0)).to be_empty
        }
      end
    end
  end
end