diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
commit | 36a59d088eca61b834191dacea009677a96c052f (patch) | |
tree | e4f33972dab5d8ef79e3944a9f403035fceea43f /spec/support_specs/helpers/migrations_helpers_spec.rb | |
parent | a1761f15ec2cae7c7f7bbda39a75494add0dfd6f (diff) |
Add latest changes from gitlab-org/gitlab@15-0-stable-eev15.0.0-rc42
Diffstat (limited to 'spec/support_specs/helpers/migrations_helpers_spec.rb')
-rw-r--r-- | spec/support_specs/helpers/migrations_helpers_spec.rb | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/spec/support_specs/helpers/migrations_helpers_spec.rb b/spec/support_specs/helpers/migrations_helpers_spec.rb new file mode 100644 index 00000000000..b82eddad9bc --- /dev/null +++ b/spec/support_specs/helpers/migrations_helpers_spec.rb @@ -0,0 +1,74 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe MigrationsHelpers do + let(:helper_class) do + Class.new.tap do |klass| + klass.include described_class + allow(klass).to receive(:metadata).and_return(metadata) + end + end + + let(:metadata) { {} } + let(:helper) { helper_class.new } + + describe '#active_record_base' do + it 'returns the main base model' do + expect(helper.active_record_base).to eq(ActiveRecord::Base) + end + + context 'ci database configured' do + before do + skip_if_multiple_databases_not_setup + end + + it 'returns the CI base model' do + expect(helper.active_record_base(database: :ci)).to eq(Ci::ApplicationRecord) + end + end + + context 'ci database not configured' do + before do + skip_if_multiple_databases_are_setup + end + + it 'returns the main base model' do + expect(helper.active_record_base(database: :ci)).to eq(ActiveRecord::Base) + end + end + + it 'raises ArgumentError for bad database argument' do + expect { helper.active_record_base(database: :non_existent) }.to raise_error(ArgumentError) + end + end + + describe '#table' do + it 'creates a class based on main base model' do + klass = helper.table(:projects) + expect(klass.connection_specification_name).to eq('ActiveRecord::Base') + end + + context 'ci database configured' do + before do + skip_if_multiple_databases_not_setup + end + + it 'create a class based on the CI base model' do + klass = helper.table(:ci_builds, database: :ci) + expect(klass.connection_specification_name).to eq('Ci::ApplicationRecord') + end + end + + context 'ci database not configured' do + before do + skip_if_multiple_databases_are_setup + end + + it 'creates a class based on main base model' do + klass = helper.table(:ci_builds, database: :ci) + expect(klass.connection_specification_name).to eq('ActiveRecord::Base') + end + end + end +end |