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
|
# frozen_string_literal: true
require 'spec_helper'
require_migration!
RSpec.describe InsertCiDailyPipelineScheduleTriggersPlanLimits do
let_it_be(:plans) { table(:plans) }
let_it_be(:plan_limits) { table(:plan_limits) }
context 'when on Gitlab.com' do
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') }
before do
allow(Gitlab).to receive(:com?).and_return(true)
plan_limits.create!(plan_id: free_plan.id)
plan_limits.create!(plan_id: bronze_plan.id)
plan_limits.create!(plan_id: silver_plan.id)
plan_limits.create!(plan_id: gold_plan.id)
end
it 'correctly migrates up and down' do
reversible_migration do |migration|
migration.before -> {
expect(plan_limits.pluck(:plan_id, :ci_daily_pipeline_schedule_triggers)).to contain_exactly(
[free_plan.id, 0],
[bronze_plan.id, 0],
[silver_plan.id, 0],
[gold_plan.id, 0]
)
}
migration.after -> {
expect(plan_limits.pluck(:plan_id, :ci_daily_pipeline_schedule_triggers)).to contain_exactly(
[free_plan.id, 24],
[bronze_plan.id, 288],
[silver_plan.id, 288],
[gold_plan.id, 288]
)
}
end
end
end
context 'when on self hosted' do
let(:free_plan) { plans.create!(name: 'free') }
before do
allow(Gitlab).to receive(:com?).and_return(false)
plan_limits.create!(plan_id: free_plan.id)
end
it 'does nothing' do
reversible_migration do |migration|
migration.before -> {
expect(plan_limits.pluck(:plan_id, :ci_daily_pipeline_schedule_triggers)).to contain_exactly(
[free_plan.id, 0]
)
}
migration.after -> {
expect(plan_limits.pluck(:plan_id, :ci_daily_pipeline_schedule_triggers)).to contain_exactly(
[free_plan.id, 0]
)
}
end
end
end
end
|