blob: 0b2f76baf1a213bc96e4e29221f41f63b4828925 (
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
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
# frozen_string_literal: true
require 'spec_helper'
require_migration!
RSpec.describe UpdateTrialPlansCiDailyPipelineScheduleTriggers, :migration do
let!(:plans) { table(:plans) }
let!(:plan_limits) { table(:plan_limits) }
let!(:premium_trial_plan) { plans.create!(name: 'premium_trial', title: 'Premium Trial') }
let!(:ultimate_trial_plan) { plans.create!(name: 'ultimate_trial', title: 'Ultimate Trial') }
describe '#up' do
let!(:premium_trial_plan_limits) { plan_limits.create!(plan_id: premium_trial_plan.id, ci_daily_pipeline_schedule_triggers: 0) }
let!(:ultimate_trial_plan_limits) { plan_limits.create!(plan_id: ultimate_trial_plan.id, ci_daily_pipeline_schedule_triggers: 0) }
context 'when the environment is dev or com' do
before do
allow(Gitlab).to receive(:dev_env_or_com?).and_return(true)
end
it 'sets the trial plan limits for ci_daily_pipeline_schedule_triggers' do
disable_migrations_output { migrate! }
expect(ultimate_trial_plan_limits.reload.ci_daily_pipeline_schedule_triggers).to eq(288)
expect(premium_trial_plan_limits.reload.ci_daily_pipeline_schedule_triggers).to eq(288)
end
it 'does not change the plan limits if the ultimate trial plan is missing' do
ultimate_trial_plan.destroy!
expect { disable_migrations_output { migrate! } }.not_to change { plan_limits.count }
expect(premium_trial_plan_limits.reload.ci_daily_pipeline_schedule_triggers).to eq(0)
end
it 'does not change the plan limits if the ultimate trial plan limits is missing' do
ultimate_trial_plan_limits.destroy!
expect { disable_migrations_output { migrate! } }.not_to change { plan_limits.count }
expect(premium_trial_plan_limits.reload.ci_daily_pipeline_schedule_triggers).to eq(0)
end
it 'does not change the plan limits if the premium trial plan is missing' do
premium_trial_plan.destroy!
expect { disable_migrations_output { migrate! } }.not_to change { plan_limits.count }
expect(ultimate_trial_plan_limits.reload.ci_daily_pipeline_schedule_triggers).to eq(0)
end
it 'does not change the plan limits if the premium trial plan limits is missing' do
premium_trial_plan_limits.destroy!
expect { disable_migrations_output { migrate! } }.not_to change { plan_limits.count }
expect(ultimate_trial_plan_limits.reload.ci_daily_pipeline_schedule_triggers).to eq(0)
end
end
context 'when the environment is anything other than dev or com' do
before do
allow(Gitlab).to receive(:dev_env_or_com?).and_return(false)
end
it 'does not update the plan limits' do
disable_migrations_output { migrate! }
expect(premium_trial_plan_limits.reload.ci_daily_pipeline_schedule_triggers).to eq(0)
expect(ultimate_trial_plan_limits.reload.ci_daily_pipeline_schedule_triggers).to eq(0)
end
end
end
describe '#down' do
let!(:premium_trial_plan_limits) { plan_limits.create!(plan_id: premium_trial_plan.id, ci_daily_pipeline_schedule_triggers: 288) }
let!(:ultimate_trial_plan_limits) { plan_limits.create!(plan_id: ultimate_trial_plan.id, ci_daily_pipeline_schedule_triggers: 288) }
context 'when the environment is dev or com' do
before do
allow(Gitlab).to receive(:dev_env_or_com?).and_return(true)
end
it 'sets the trial plan limits ci_daily_pipeline_schedule_triggers to zero' do
migrate_down!
expect(ultimate_trial_plan_limits.reload.ci_daily_pipeline_schedule_triggers).to eq(0)
expect(premium_trial_plan_limits.reload.ci_daily_pipeline_schedule_triggers).to eq(0)
end
it 'does not change the plan limits if the ultimate trial plan is missing' do
ultimate_trial_plan.destroy!
expect { migrate_down! }.not_to change { plan_limits.count }
expect(premium_trial_plan_limits.reload.ci_daily_pipeline_schedule_triggers).to eq(288)
end
it 'does not change the plan limits if the ultimate trial plan limits is missing' do
ultimate_trial_plan_limits.destroy!
expect { migrate_down! }.not_to change { plan_limits.count }
expect(premium_trial_plan_limits.reload.ci_daily_pipeline_schedule_triggers).to eq(288)
end
it 'does not change the plan limits if the premium trial plan is missing' do
premium_trial_plan.destroy!
expect { migrate_down! }.not_to change { plan_limits.count }
expect(ultimate_trial_plan_limits.reload.ci_daily_pipeline_schedule_triggers).to eq(288)
end
it 'does not change the plan limits if the premium trial plan limits is missing' do
premium_trial_plan_limits.destroy!
expect { migrate_down! }.not_to change { plan_limits.count }
expect(ultimate_trial_plan_limits.reload.ci_daily_pipeline_schedule_triggers).to eq(288)
end
end
context 'when the environment is anything other than dev or com' do
before do
allow(Gitlab).to receive(:dev_env_or_com?).and_return(false)
end
it 'does not change the ultimate trial plan limits' do
migrate_down!
expect(ultimate_trial_plan_limits.reload.ci_daily_pipeline_schedule_triggers).to eq(288)
expect(premium_trial_plan_limits.reload.ci_daily_pipeline_schedule_triggers).to eq(288)
end
end
end
def migrate_down!
disable_migrations_output do
migrate!
described_class.new.down
end
end
end
|