From a3444843ed5b780b5f3e71904e8f735058975899 Mon Sep 17 00:00:00 2001 From: fatkodima Date: Wed, 18 Dec 2024 00:35:32 +0200 Subject: [PATCH] Fix incorrect_dependent_option checker for broken associations --- .../detectors/incorrect_dependent_option.rb | 2 +- .../incorrect_dependent_option_test.rb | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/active_record_doctor/detectors/incorrect_dependent_option.rb b/lib/active_record_doctor/detectors/incorrect_dependent_option.rb index 765306d..fc580fb 100644 --- a/lib/active_record_doctor/detectors/incorrect_dependent_option.rb +++ b/lib/active_record_doctor/detectors/incorrect_dependent_option.rb @@ -77,8 +77,8 @@ def detect associated_models: [through_association.klass.name], associated_models_type: "join" ) - next end + next end associated_models, associated_models_type = diff --git a/test/active_record_doctor/detectors/incorrect_dependent_option_test.rb b/test/active_record_doctor/detectors/incorrect_dependent_option_test.rb index 70dbdd9..8003cec 100644 --- a/test/active_record_doctor/detectors/incorrect_dependent_option_test.rb +++ b/test/active_record_doctor/detectors/incorrect_dependent_option_test.rb @@ -405,6 +405,25 @@ def test_has_through_associations_when_join_model_incomplete OUTPUT end + def test_has_through_associations_with_bad_source + Context.create_table(:users).define_model do + has_many :posts + has_many :comments, through: :posts, source: :non_existent + end + + Context.create_table(:posts) do |t| + t.references :users + end.define_model do + has_many :comments + end + + Context.create_table(:comments) do |t| + t.references :posts + end.define_model + + refute_problems + end + def test_destroy_async_and_foreign_key_exists Context.create_table(:companies) do end.define_model do