aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations/has_many_through_associations_test.rb
diff options
context:
space:
mode:
authorZach Dennis <zach.dennis@gmail.com>2008-10-04 15:42:36 +0100
committerPratik Naik <pratiknaik@gmail.com>2008-10-04 17:49:39 +0100
commit95e1cf4812d4b964d7ab0fdf4bfa31177d27909c (patch)
tree82d7154cbf293128a06fafe040cf68f4d9d18f7f /activerecord/test/cases/associations/has_many_through_associations_test.rb
parent7659fb6a2b638703a99a63033d947d19089a6b85 (diff)
downloadrails-95e1cf4812d4b964d7ab0fdf4bfa31177d27909c.tar.gz
rails-95e1cf4812d4b964d7ab0fdf4bfa31177d27909c.tar.bz2
rails-95e1cf4812d4b964d7ab0fdf4bfa31177d27909c.zip
Fix has_many :through when the source is a belongs_to association. [#323 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'activerecord/test/cases/associations/has_many_through_associations_test.rb')
-rw-r--r--activerecord/test/cases/associations/has_many_through_associations_test.rb17
1 files changed, 16 insertions, 1 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 12cce98c26..a07f4bcbdd 100644
--- a/activerecord/test/cases/associations/has_many_through_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb
@@ -5,7 +5,7 @@ require 'models/reader'
require 'models/comment'
class HasManyThroughAssociationsTest < ActiveRecord::TestCase
- fixtures :posts, :readers, :people, :comments
+ fixtures :posts, :readers, :people, :comments, :authors
def test_associate_existing
assert_queries(2) { posts(:thinking);people(:david) }
@@ -229,4 +229,19 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
end
end
end
+
+ def test_has_many_association_through_a_belongs_to_association_where_the_association_doesnt_exist
+ author = authors(:mary)
+ post = Post.create!(:title => "TITLE", :body => "BODY")
+ assert_equal [], post.author_favorites
+ end
+
+ def test_has_many_association_through_a_belongs_to_association
+ author = authors(:mary)
+ post = Post.create!(:author => author, :title => "TITLE", :body => "BODY")
+ author.author_favorites.create(:favorite_author_id => 1)
+ author.author_favorites.create(:favorite_author_id => 2)
+ author.author_favorites.create(:favorite_author_id => 3)
+ assert_equal post.author.author_favorites, post.author_favorites
+ end
end