diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-09-03 16:53:50 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-09-03 16:53:50 -0700 |
commit | 489a0890b6dbb8c7954e2a3b120fe31de64f156c (patch) | |
tree | 664ce6fffa9ea2dde5d1c0235431b7e80fb602c0 /activerecord | |
parent | 1f006cd5f10663286e70b4c3e972fba91ac8c9f9 (diff) | |
download | rails-489a0890b6dbb8c7954e2a3b120fe31de64f156c.tar.gz rails-489a0890b6dbb8c7954e2a3b120fe31de64f156c.tar.bz2 rails-489a0890b6dbb8c7954e2a3b120fe31de64f156c.zip |
adding a hm:t test for singleton ar objects
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/test/cases/associations/has_many_through_associations_test.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/has_many_through_associations_test.rb b/activerecord/test/cases/associations/has_many_through_associations_test.rb index c00cae5750..508faa9437 100644 --- a/activerecord/test/cases/associations/has_many_through_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb @@ -37,6 +37,33 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase Reader.create :person_id => 0, :post_id => 0 end + def make_model(name) + Class.new(ActiveRecord::Base) { define_singleton_method(:name) { name } } + end + + def test_singleton_has_many_through + book = make_model "Book" + subscription = make_model "Subscription" + subscriber = make_model "Subscriber" + + subscriber.primary_key = 'nick' + subscription.belongs_to :book, class: book + subscription.belongs_to :subscriber, class: subscriber + + book.has_many :subscriptions, class: subscription + book.has_many :subscribers, through: :subscriptions, class: subscriber + + anonbook = book.first + namebook = Book.find anonbook.id + + assert_operator anonbook.subscribers.count, :>, 0 + anonbook.subscribers.each do |s| + assert_instance_of subscriber, s + end + assert_equal namebook.subscribers.map(&:id).sort, + anonbook.subscribers.map(&:id).sort + end + def test_pk_is_not_required_for_join post = Post.includes(:scategories).first post2 = Post.includes(:categories).first |