Skip to content

Commit

Permalink
Merge pull request rails#17575 from shikshachauhan/make-habtm-consistent
Browse files Browse the repository at this point in the history
Allow class_name option in habtm to be consistent with other association...
  • Loading branch information
rafaelfranca committed Nov 19, 2014
2 parents 70c2bf9 + 07e0d8c commit 7a5a3a8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Expand Up @@ -110,7 +110,7 @@ def belongs_to_options(options)
rhs_options = {}

if options.key? :class_name
rhs_options[:foreign_key] = options[:class_name].foreign_key
rhs_options[:foreign_key] = options[:class_name].to_s.foreign_key
rhs_options[:class_name] = options[:class_name]
end

Expand Down
Expand Up @@ -79,6 +79,10 @@ class SubDeveloper < Developer
:association_foreign_key => "developer_id"
end

class DeveloperWithSymbolClassName < Developer
has_and_belongs_to_many :projects, class_name: :ProjectWithSymbolsForKeys
end

class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase
fixtures :accounts, :companies, :categories, :posts, :categories_posts, :developers, :projects, :developers_projects,
:parrots, :pirates, :parrots_pirates, :treasures, :price_estimates, :tags, :taggings, :computers
Expand Down Expand Up @@ -892,4 +896,10 @@ def test_habtm_with_reflection_using_class_name_and_fixtures
assert_not_nil File.read(File.expand_path("../../../fixtures/developers.yml", __FILE__)).index("shared_computers")
assert_equal developers(:david).shared_computers.first, computers(:laptop)
end

def test_with_symbol_class_name
assert_nothing_raised NoMethodError do
DeveloperWithSymbolClassName.new
end
end
end

0 comments on commit 7a5a3a8

Please sign in to comment.