aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2010-10-12 16:53:22 +0100
committerJon Leighton <j@jonathanleighton.com>2010-10-12 16:53:22 +0100
commit6a016a551109ed2ef78fff8f74aef6b1f4ae96a9 (patch)
treee16bf8db6d399ac0f383dab9247b1a45effe6959 /activerecord/test/cases
parent1777600e6e11e553ad97b7bc89e4b19e992eb3d3 (diff)
downloadrails-6a016a551109ed2ef78fff8f74aef6b1f4ae96a9.tar.gz
rails-6a016a551109ed2ef78fff8f74aef6b1f4ae96a9.tar.bz2
rails-6a016a551109ed2ef78fff8f74aef6b1f4ae96a9.zip
Add test_has_many_through_has_one_through
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/associations/nested_has_many_through_associations_test.rb16
1 files changed, 14 insertions, 2 deletions
diff --git a/activerecord/test/cases/associations/nested_has_many_through_associations_test.rb b/activerecord/test/cases/associations/nested_has_many_through_associations_test.rb
index 4fab426696..c1e8a4b1bf 100644
--- a/activerecord/test/cases/associations/nested_has_many_through_associations_test.rb
+++ b/activerecord/test/cases/associations/nested_has_many_through_associations_test.rb
@@ -21,6 +21,8 @@ require 'models/rating'
require 'models/member'
require 'models/member_detail'
require 'models/member_type'
+require 'models/sponsor'
+require 'models/club'
# NOTE: Some of these tests might not really test "nested" HMT associations, as opposed to ones which
# are just one level deep. But it's all the same thing really, as the "nested" code is being
@@ -30,7 +32,7 @@ require 'models/member_type'
class NestedHasManyThroughAssociationsTest < ActiveRecord::TestCase
fixtures :authors, :books, :posts, :subscriptions, :subscribers, :tags, :taggings,
:people, :readers, :references, :jobs, :ratings, :comments, :members, :member_details,
- :member_types
+ :member_types, :sponsors, :clubs
# Through associations can either use the has_many or has_one macros.
#
@@ -97,9 +99,19 @@ class NestedHasManyThroughAssociationsTest < ActiveRecord::TestCase
assert_equal [member_types(:founding)], members.first.nested_member_types
end
- # TODO: has_many through
+ # has_many through
# Source: has_one
# Through: has_one through
+ def test_has_many_through_has_one_through
+ assert_equal [sponsors(:moustache_club_sponsor_for_groucho)], members(:groucho).nested_sponsors
+
+ members = Member.joins(:nested_sponsors).where('sponsors.id' => sponsors(:moustache_club_sponsor_for_groucho).id)
+ assert_equal [members(:groucho)], members
+
+ # TODO: Make this work
+ # members = Member.includes(:nested_sponsors)
+ # assert_equal [sponsors(:moustache_club_sponsor_for_groucho)], members.first.nested_sponsors
+ end
# TODO: has_many through
# Source: has_many through