Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#61776] Configure active_record_doctor to detect mismatched fk constraints and association dependent option #18075

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,9 @@ group :development, :test do

# i18n-tasks helps find and manage missing and unused translations.
gem "i18n-tasks", "~> 1.0.13", require: false

# Active Record Doctor helps to keep the database in good shape.
gem "active_record_doctor", "~> 1.15.0"
end

gem "bootsnap", "~> 1.18.0", require: false
Expand Down
6 changes: 5 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ GEM
erubi (~> 1.11)
rails-dom-testing (~> 2.2)
rails-html-sanitizer (~> 1.6)
active_record_doctor (1.15.0)
activerecord (>= 4.2.0)
activejob (7.1.5.1)
activesupport (= 7.1.5.1)
globalid (>= 0.3.6)
Expand Down Expand Up @@ -1267,6 +1269,7 @@ PLATFORMS

DEPENDENCIES
actionpack-xml_parser (~> 2.0.0)
active_record_doctor (~> 1.15.0)
activemodel-serializers-xml (~> 1.0.1)
activerecord-import (~> 2.1.0)
activerecord-nulldb-adapter (~> 1.1.0)
Expand Down Expand Up @@ -1486,6 +1489,7 @@ CHECKSUMS
actionpack-xml_parser (2.0.1) sha256=40cb461ee99445314ab580a783fb7413580deb8b28113c9e70ecd7c1b334d5e6
actiontext (7.1.5.1) sha256=b8e261cfad5bc6a78b3f15be5e7c7f32190041b3dc6f027a3a353b4392d2f7ec
actionview (7.1.5.1) sha256=8c559a213501798e29b50b5341a643a70bbf6fa0aa2abaf571d0efc59dc4f6aa
active_record_doctor (1.15.0) sha256=614a49e259a679d17cbc62dead9217acaf7191a371115606132473123b426b13
activejob (7.1.5.1) sha256=7633376c857f4c491d06b5a7f5d86d9f07afc595398354a3f1abe80eb7e35767
activemodel (7.1.5.1) sha256=74727466854a7fbdfe8f2702ca3112b23877500d4926bf7e02e921ad542191f1
activemodel-serializers-xml (1.0.3) sha256=fa1b16305e7254cc58a59c68833e3c0a593a59c8ab95d3be5aaea7cd9416c397
Expand Down Expand Up @@ -1687,7 +1691,7 @@ CHECKSUMS
marcel (1.0.4) sha256=0d5649feb64b8f19f3d3468b96c680bae9746335d02194270287868a661516a4
markly (0.12.1) sha256=fda3a53ec29e349e9c30e34cf9da322aa260d66627f75b2d3a8ad9633e5cbab9
matrix (0.4.2) sha256=71083ccbd67a14a43bfa78d3e4dc0f4b503b9cc18e5b4b1d686dc0f9ef7c4cc0
md_to_pdf (0.1.5)
md_to_pdf (0.2.0)
messagebird-rest (1.4.2) sha256=1501e16ad76c87558f20f3b26cb39d05f587b349b44b8bf8056b040e9b495301
meta-tags (2.22.1) sha256=e5ae1febbd320d396c7226d7edb868e5d63466c14b9c8b06622a1a74e6dce354
method_source (1.1.0) sha256=181301c9c45b731b4769bc81e8860e72f9161ad7d66dd99103c9ab84f560f5c5
Expand Down
8 changes: 5 additions & 3 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,16 @@ class User < Principal
belongs_to :ldap_auth_source, optional: true

# Authorized OAuth grants
has_many :oauth_grants,
has_many :oauth_grants, # rubocop:disable Rails/InverseOf
class_name: "Doorkeeper::AccessGrant",
foreign_key: "resource_owner_id"
foreign_key: "resource_owner_id",
dependent: :delete_all

# User-defined oauth applications
has_many :oauth_applications,
class_name: "Doorkeeper::Application",
as: :owner
as: :owner,
dependent: :destroy

# Meeting memberships
has_many :meeting_participants,
Expand Down
2 changes: 2 additions & 0 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
describe "Associations" do
it { is_expected.to have_many(:emoji_reactions).dependent(:destroy) }
it { is_expected.to have_many(:reminders).with_foreign_key(:creator_id).dependent(:destroy).inverse_of(:creator) }
it { is_expected.to have_many(:oauth_grants).with_foreign_key(:resource_owner_id).dependent(:delete_all) }
it { is_expected.to have_many(:oauth_applications).dependent(:destroy) }
end

describe "with long but allowed attributes" do
Expand Down
Loading