Commit b6a93e48 authored by Sean McGivern's avatar Sean McGivern

Merge branch '334528-fix-seed-for-plans' into 'master'

Fix seeding of default plan

See merge request gitlab-org/gitlab!64793
parents beb494e4 088bfc89
......@@ -14,7 +14,7 @@ class Plan < ApplicationRecord
Gitlab::SafeRequestStore.fetch(:plan_default) do
# find_by allows us to find object (cheaply) against replica DB
# safe_find_or_create_by does stick to primary DB
find_by(name: DEFAULT) || safe_find_or_create_by(name: DEFAULT)
find_by(name: DEFAULT) || safe_find_or_create_by(name: DEFAULT) { |plan| plan.title = DEFAULT.titleize }
end
end
......
# frozen_string_literal: true
Gitlab::Seeder.quiet do
Plan.create!(name: Plan::DEFAULT, title: Plan::DEFAULT.titleize)
# The default plan could already be created if Plan.default was called
Plan.safe_find_or_create_by!(name: Plan::DEFAULT) { |plan| plan.title = Plan::DEFAULT.titleize }
Plan.create!(name: Plan::FREE, title: Plan::FREE.titleize) if Gitlab.com?
end
......@@ -15,6 +15,29 @@ RSpec.describe Plan do
end
end
describe '#default' do
context 'when default plan exists' do
let!(:default_plan) { create(:default_plan) }
it 'returns default plan' do
expect(described_class.default).to eq(default_plan)
end
end
context 'when default plan does not exist' do
it 'creates default plan' do
expect { described_class.default }.to change { Plan.count }.by(1)
end
it 'creates plan with correct attributes' do
plan = described_class.default
expect(plan.name).to eq(Plan::DEFAULT)
expect(plan.title).to eq(Plan::DEFAULT.titleize)
end
end
end
context 'when updating plan limits' do
let(:plan) { described_class.default }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment