Skip to content

Rework STI checks in model specs

Peter Leitzen requested to merge pl-spec-model-disable-sti into master

What does this MR do and why?

This MR is a follow-up from !136649 (merged) and !138413 (merged) and improves how the use of STI in models is checked:

  1. It maps spec/models/every_model_spec.rb to every model change
  2. It extracts STI check into a shared examples which is run in every model spec (via type: :model metadata)
    • This helps local feedback so the STI check is run whenever a model spec is run
  3. Remove ApplicationRecord#new patch from DisablesSti concern
    • This functionality is now covered by shared example

Using SKIP_STI_CHECK=1 to disable this check still works!

Refs #432960 (comment 1679921619).

How to set up and validate locally

bundle exec tff -f tests.yml app/models/project.rb

bundle exec tff -f tests.yml ee/app/models/weight_note.rb

bundle exec rspec spec/models/every_model_spec.rb

bundle exec rspec spec/models/project_spec.rb -e 'does not allow STI'

SKIP_STI_CHECK=1 bundle exec rspec spec/models/project_spec.rb -e 'does not allow STI'

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Peter Leitzen

Merge request reports