diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-12-19 14:01:45 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-12-19 14:01:45 +0300 |
commit | 9297025d0b7ddf095eb618dfaaab2ff8f2018d8b (patch) | |
tree | 865198c01d1824a9b098127baa3ab980c9cd2c06 /spec/support/shared_examples/models/disable_sti_shared_examples.rb | |
parent | 6372471f43ee03c05a7c1f8b0c6ac6b8a7431dbe (diff) |
Add latest changes from gitlab-org/gitlab@16-7-stable-eev16.7.0-rc42
Diffstat (limited to 'spec/support/shared_examples/models/disable_sti_shared_examples.rb')
-rw-r--r-- | spec/support/shared_examples/models/disable_sti_shared_examples.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/spec/support/shared_examples/models/disable_sti_shared_examples.rb b/spec/support/shared_examples/models/disable_sti_shared_examples.rb new file mode 100644 index 00000000000..090592827d1 --- /dev/null +++ b/spec/support/shared_examples/models/disable_sti_shared_examples.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +# Checks whether STI is disabled in +models+. +# +# Parameter: +# - models: List of model classes +RSpec.shared_examples 'Model disables STI' do + skip_sti_check = Gitlab::Utils.to_boolean(ENV['SKIP_STI_CHECK'], default: false) + + it 'does not allow STI', :aggregate_failures, unless: skip_sti_check do + models.each do |model| + next unless model + next unless model < ApplicationRecord + next if model == model.base_class + next if model.allow_legacy_sti_class + + expect(model).not_to have_attribute(model.inheritance_column), + "Do not use Single Table Inheritance (`#{model.name}` inherits `#{model.base_class.name}`). " \ + "See https://docs.gitlab.com/ee/development/database/single_table_inheritance.html" + end + end +end + +RSpec.shared_examples 'STI disabled', type: :model do # rubocop:disable RSpec/SharedGroupsMetadata -- Shared example is run within every spec tagged `type: :model` + include_examples 'Model disables STI' do + let(:models) { [described_class] } + end +end |