diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-09-03 14:16:29 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-09-03 14:16:29 -0700 |
commit | 1f006cd5f10663286e70b4c3e972fba91ac8c9f9 (patch) | |
tree | f5b44cc39be164115fba4f8df580f45027b12eda /activerecord/test/cases | |
parent | c64a001dcc9eb1b066ca3ce553c5d20988458e8c (diff) | |
download | rails-1f006cd5f10663286e70b4c3e972fba91ac8c9f9.tar.gz rails-1f006cd5f10663286e70b4c3e972fba91ac8c9f9.tar.bz2 rails-1f006cd5f10663286e70b4c3e972fba91ac8c9f9.zip |
support anonymous classes on has_many associations
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/associations/has_many_associations_test.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index ce51853bf3..4c0fa88917 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -45,6 +45,24 @@ class HasManyAssociationsTest < ActiveRecord::TestCase Client.destroyed_client_ids.clear end + def test_anonymous_has_many + developer = Class.new(ActiveRecord::Base) { + self.table_name = 'developers' + dev = self + + developer_project = Class.new(ActiveRecord::Base) { + self.table_name = 'developers_projects' + belongs_to :developer, :class => dev + } + has_many :developer_projects, :class => developer_project, :foreign_key => 'developer_id' + } + dev = developer.first + named = Developer.find(dev.id) + assert_operator dev.developer_projects.count, :>, 0 + assert_equal named.projects.map(&:id).sort, + dev.developer_projects.map(&:project_id).sort + end + def test_create_from_association_should_respect_default_scope car = Car.create(:name => 'honda') assert_equal 'honda', car.name |