Permalink
Browse files

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
  • Loading branch information...
meinac committed Feb 19, 2016
1 parent 7506f33 commit 94821b4bd10464d52b471380c49f85fac43a8ab7
@@ -28,7 +28,7 @@ def self.build(lhs_class, name, options)
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
@@ -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 @@ def test_habtm_with_reflection_using_class_name_and_fixtures
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

0 comments on commit 94821b4

Please sign in to comment.