diff options
author | Mehmet Emin İNAÇ <mehmetemininac@gmail.com> | 2016-02-19 04:42:59 +0200 |
---|---|---|
committer | Mehmet Emin İNAÇ <mehmetemininac@gmail.com> | 2016-10-27 11:47:14 +0300 |
commit | 94821b4bd10464d52b471380c49f85fac43a8ab7 (patch) | |
tree | 9b856be2bcb83936145bc8ef6a5a9f1af32c063a /activerecord/test | |
parent | 7506f3390683fd1329e60385515c3c55b39ff1d5 (diff) | |
download | rails-94821b4bd10464d52b471380c49f85fac43a8ab7.tar.gz rails-94821b4bd10464d52b471380c49f85fac43a8ab7.tar.bz2 rails-94821b4bd10464d52b471380c49f85fac43a8ab7.zip |
Fix HABTM associations join table resolver bug on constants and symbols
Using Constant and symbol class_name option for associations are valid but raises exception on HABTM associations.
There was a test case which tries to cover symbol class_name usage but doesn't cover correctly. Fixed both symbol usage and constant usage as well.
These are all working as expected now;
```
has_and_belongs_to_many :foos, class_name: 'Foo'
has_and_belongs_to_many :foos, class_name: :Foo
has_and_belongs_to_many :foos, class_name: Foo
```
Closes #23767
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb index 06fc7a4388..8aab7cfa47 100644 --- a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb @@ -86,6 +86,10 @@ class DeveloperWithSymbolClassName < Developer has_and_belongs_to_many :projects, class_name: :ProjectWithSymbolsForKeys end +class DeveloperWithConstantClassName < Developer + has_and_belongs_to_many :projects, class_name: ProjectWithSymbolsForKeys +end + class DeveloperWithExtendOption < Developer module NamedExtension def category @@ -939,7 +943,15 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase def test_with_symbol_class_name assert_nothing_raised do - DeveloperWithSymbolClassName.new + developer = DeveloperWithSymbolClassName.new + developer.projects + end + end + + def test_with_constant_class_name + assert_nothing_raised do + developer = DeveloperWithConstantClassName.new + developer.projects end end |