diff options
author | Arthur Nogueira Neves <github@arthurnn.com> | 2016-10-27 22:31:44 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-27 22:31:44 -0400 |
commit | d48b4489204b96566345f059126556c03bb98e0c (patch) | |
tree | 778b7031aae7c9eddc853839722280d68188f546 | |
parent | 007e50d8e5a900547471b6c4ec79d9d217682c5d (diff) | |
parent | 94821b4bd10464d52b471380c49f85fac43a8ab7 (diff) | |
download | rails-d48b4489204b96566345f059126556c03bb98e0c.tar.gz rails-d48b4489204b96566345f059126556c03bb98e0c.tar.bz2 rails-d48b4489204b96566345f059126556c03bb98e0c.zip |
Merge pull request #23770 from meinac/fix_habtm_symbol_class_name
Fix HABTM associations join table resolver bug on constants and symbols
-rw-r--r-- | activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb | 14 |
2 files changed, 14 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb b/activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb index 047292b2bd..42a90b449c 100644 --- a/activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb +++ b/activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb @@ -28,7 +28,7 @@ module ActiveRecord::Associations::Builder # :nodoc: class_name = options.fetch(:class_name) { name.to_s.camelize.singularize } - KnownClass.new lhs_class, class_name + KnownClass.new lhs_class, class_name.to_s end end end 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 |