2019-12-26 22:10:19 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
require Rails.root.join('db', 'migrate', '20191030152934_move_limits_from_plans.rb')
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe MoveLimitsFromPlans do
|
2019-12-26 22:10:19 +05:30
|
|
|
let(:plans) { table(:plans) }
|
|
|
|
let(:plan_limits) { table(:plan_limits) }
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
let!(:gold_plan) { plans.create!(name: 'gold', title: 'Gold', active_pipelines_limit: 20, pipeline_size_limit: 21, active_jobs_limit: 22) }
|
|
|
|
let!(:silver_plan) { plans.create!(name: 'silver', title: 'Silver', active_pipelines_limit: 30, pipeline_size_limit: 31, active_jobs_limit: 32) }
|
|
|
|
let!(:bronze_plan) { plans.create!(name: 'bronze', title: 'Bronze', active_pipelines_limit: 40, pipeline_size_limit: 41, active_jobs_limit: 42) }
|
|
|
|
let!(:free_plan) { plans.create!(name: 'free', title: 'Free', active_pipelines_limit: 50, pipeline_size_limit: 51, active_jobs_limit: 52) }
|
|
|
|
let!(:other_plan) { plans.create!(name: 'other', title: 'Other', active_pipelines_limit: nil, pipeline_size_limit: nil, active_jobs_limit: 0) }
|
2019-12-26 22:10:19 +05:30
|
|
|
|
|
|
|
describe 'migrate' do
|
|
|
|
it 'populates plan_limits from all the records in plans' do
|
2020-11-24 15:15:51 +05:30
|
|
|
expect { migrate! }.to change { plan_limits.count }.by 5
|
2019-12-26 22:10:19 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'copies plan limits and plan.id into to plan_limits table' do
|
|
|
|
migrate!
|
|
|
|
|
|
|
|
new_data = plan_limits.pluck(:plan_id, :ci_active_pipelines, :ci_pipeline_size, :ci_active_jobs)
|
|
|
|
expected_data = [
|
|
|
|
[gold_plan.id, 20, 21, 22],
|
|
|
|
[silver_plan.id, 30, 31, 32],
|
|
|
|
[bronze_plan.id, 40, 41, 42],
|
|
|
|
[free_plan.id, 50, 51, 52],
|
|
|
|
[other_plan.id, 0, 0, 0]
|
|
|
|
]
|
|
|
|
expect(new_data).to contain_exactly(*expected_data)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|