Skip to content

Commit 8736fc7

Browse files
authored
Fix incorrect_dependent_option on broken associations (#202)
1 parent 38753de commit 8736fc7

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/active_record_doctor/detectors/incorrect_dependent_option.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ def detect
7777
associated_models: [through_association.klass.name],
7878
associated_models_type: "join"
7979
)
80-
next
8180
end
81+
next
8282
end
8383

8484
associated_models, associated_models_type =

test/active_record_doctor/detectors/incorrect_dependent_option_test.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,25 @@ def test_has_through_associations_when_join_model_incomplete
405405
OUTPUT
406406
end
407407

408+
def test_has_through_associations_with_bad_source
409+
Context.create_table(:users).define_model do
410+
has_many :posts
411+
has_many :comments, through: :posts, source: :non_existent
412+
end
413+
414+
Context.create_table(:posts) do |t|
415+
t.references :users
416+
end.define_model do
417+
has_many :comments
418+
end
419+
420+
Context.create_table(:comments) do |t|
421+
t.references :posts
422+
end.define_model
423+
424+
refute_problems
425+
end
426+
408427
def test_destroy_async_and_foreign_key_exists
409428
Context.create_table(:companies) do
410429
end.define_model do

0 commit comments

Comments
 (0)