Skip to content

Commit bc7030c

Browse files
committed
Add regression tests for keys on nested associations
This adds the regressions tests from issue rails#15893 to master. It's checking that both strings and symbols are accepted as keys for nested associations.
1 parent da57d0b commit bc7030c

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

activerecord/test/cases/reflection_test.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,38 @@ def test_join_table_can_be_overridden
412412
assert_equal 'product_categories', reflection.join_table
413413
end
414414

415+
def test_includes_accepts_symbols
416+
hotel = Hotel.create!
417+
department = hotel.departments.create!
418+
department.chefs.create!
419+
420+
assert_nothing_raised do
421+
assert_equal department.chefs, Hotel.includes([departments: :chefs]).first.chefs
422+
end
423+
end
424+
425+
def test_includes_accepts_strings
426+
hotel = Hotel.create!
427+
department = hotel.departments.create!
428+
department.chefs.create!
429+
430+
assert_nothing_raised do
431+
assert_equal department.chefs, Hotel.includes(['departments' => 'chefs']).first.chefs
432+
end
433+
end
434+
435+
def test_reflect_on_association_accepts_symbols
436+
assert_nothing_raised do
437+
assert_equal Hotel.reflect_on_association(:departments).name, :departments
438+
end
439+
end
440+
441+
def test_reflect_on_association_accepts_strings
442+
assert_nothing_raised do
443+
assert_equal Hotel.reflect_on_association("departments").name, :departments
444+
end
445+
end
446+
415447
private
416448
def assert_reflection(klass, association, options)
417449
assert reflection = klass.reflect_on_association(association)

0 commit comments

Comments
 (0)