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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-07-13 21:08:57 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-07-13 21:08:57 +0300
commite9606d7f51144274f9a390c9dd683200daab8eed (patch)
treeb87cf29dc2fb63ea6ed519dabb3f46b06981c737 /spec/migrations
parente1189e4c3b8bd5535104f458f5af7505789eac00 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/migrations')
-rw-r--r--spec/migrations/add_premium_and_ultimate_plan_limits_spec.rb86
1 files changed, 86 insertions, 0 deletions
diff --git a/spec/migrations/add_premium_and_ultimate_plan_limits_spec.rb b/spec/migrations/add_premium_and_ultimate_plan_limits_spec.rb
new file mode 100644
index 00000000000..fb62fc3ca02
--- /dev/null
+++ b/spec/migrations/add_premium_and_ultimate_plan_limits_spec.rb
@@ -0,0 +1,86 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+require_migration!
+
+RSpec.describe AddPremiumAndUltimatePlanLimits, :migration do
+ shared_examples_for 'a migration that does not alter plans or plan limits' do
+ it do
+ expect { migrate! }.not_to change {
+ [
+ AddPremiumAndUltimatePlanLimits::Plan.count,
+ AddPremiumAndUltimatePlanLimits::PlanLimits.count
+ ]
+ }
+ end
+ end
+
+ describe '#up' do
+ context 'when not .com?' do
+ before do
+ allow(Gitlab).to receive(:com?).and_return false
+ end
+
+ it_behaves_like 'a migration that does not alter plans or plan limits'
+ end
+
+ context 'when .com?' do
+ before do
+ allow(Gitlab).to receive(:com?).and_return true
+ end
+
+ context 'when source plan does not exist' do
+ it_behaves_like 'a migration that does not alter plans or plan limits'
+ end
+
+ context 'when target plan does not exist' do
+ before do
+ table(:plans).create!(name: 'silver', title: 'Silver')
+ table(:plans).create!(name: 'gold', title: 'Gold')
+ end
+
+ it_behaves_like 'a migration that does not alter plans or plan limits'
+ end
+
+ context 'when source and target plans exist' do
+ let!(:silver) { table(:plans).create!(name: 'silver', title: 'Silver') }
+ let!(:gold) { table(:plans).create!(name: 'gold', title: 'Gold') }
+ let!(:premium) { table(:plans).create!(name: 'premium', title: 'Premium') }
+ let!(:ultimate) { table(:plans).create!(name: 'ultimate', title: 'Ultimate') }
+
+ let!(:silver_limits) { table(:plan_limits).create!(plan_id: silver.id, storage_size_limit: 111) }
+ let!(:gold_limits) { table(:plan_limits).create!(plan_id: gold.id, storage_size_limit: 222) }
+
+ context 'when target has plan limits' do
+ before do
+ table(:plan_limits).create!(plan_id: premium.id, storage_size_limit: 999)
+ table(:plan_limits).create!(plan_id: ultimate.id, storage_size_limit: 999)
+ end
+
+ it 'does not overwrite the limits' do
+ expect { migrate! }.not_to change {
+ [
+ AddPremiumAndUltimatePlanLimits::Plan.count,
+ AddPremiumAndUltimatePlanLimits::PlanLimits.pluck(:id, :storage_size_limit).sort
+ ]
+ }
+ end
+ end
+
+ context 'when target has no plan limits' do
+ it 'creates plan limits from the source plan' do
+ migrate!
+
+ expect(AddPremiumAndUltimatePlanLimits::PlanLimits.pluck(:plan_id, :storage_size_limit)).to match_array([
+ [silver.id, silver_limits.storage_size_limit],
+ [gold.id, gold_limits.storage_size_limit],
+ [premium.id, silver_limits.storage_size_limit],
+ [ultimate.id, gold_limits.storage_size_limit]
+ ])
+ end
+ end
+ end
+ end
+ end
+end