Skip to content
Browse files

adding a hm:t test for singleton ar objects

  • Loading branch information...
1 parent 1f006cd commit 489a0890b6dbb8c7954e2a3b120fe31de64f156c @tenderlove tenderlove committed Sep 3, 2013
Showing with 27 additions and 0 deletions.
  1. +27 −0 activerecord/test/cases/associations/has_many_through_associations_test.rb
View
27 activerecord/test/cases/associations/has_many_through_associations_test.rb
@@ -37,6 +37,33 @@ def setup
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

0 comments on commit 489a089

Please sign in to comment.
Something went wrong with that request. Please try again.