aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/associations_join_model_test.rb
diff options
context:
space:
mode:
authorRick Olson <technoweenie@gmail.com>2006-03-21 01:07:16 +0000
committerRick Olson <technoweenie@gmail.com>2006-03-21 01:07:16 +0000
commitc8470f8a5b74eefd498397a8effdf37b4dc28674 (patch)
tree70162f5690e6f0a757fb5b7f9d85e1acb818fd0a /activerecord/test/associations_join_model_test.rb
parentd15550aeccd5c10d7c734c523116e3da9f4b13e8 (diff)
downloadrails-c8470f8a5b74eefd498397a8effdf37b4dc28674.tar.gz
rails-c8470f8a5b74eefd498397a8effdf37b4dc28674.tar.bz2
rails-c8470f8a5b74eefd498397a8effdf37b4dc28674.zip
add self referential has_many :through example [Rick]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4006 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test/associations_join_model_test.rb')
-rw-r--r--activerecord/test/associations_join_model_test.rb13
1 files changed, 12 insertions, 1 deletions
diff --git a/activerecord/test/associations_join_model_test.rb b/activerecord/test/associations_join_model_test.rb
index ee99d77931..bbe88cfbd5 100644
--- a/activerecord/test/associations_join_model_test.rb
+++ b/activerecord/test/associations_join_model_test.rb
@@ -9,7 +9,7 @@ require 'fixtures/categorization'
class AssociationsJoinModelTest < Test::Unit::TestCase
self.use_transactional_fixtures = false
- fixtures :posts, :authors, :categories, :categorizations, :comments, :tags, :taggings
+ fixtures :posts, :authors, :categories, :categorizations, :comments, :tags, :taggings, :author_favorites
def test_has_many
assert_equal categories(:general), authors(:david).categories.first
@@ -294,6 +294,17 @@ class AssociationsJoinModelTest < Test::Unit::TestCase
end
end
+ def test_self_referential_has_many_through
+ assert_equal [authors(:mary)], authors(:david).favorite_authors
+ assert_equal [], authors(:mary).favorite_authors
+ end
+
+ def test_add_to_self_referential_has_many_through
+ new_author = Author.create(:name => "Bob")
+ authors(:david).author_favorites.create :favorite_author => new_author
+ assert_equal [new_author, authors(:mary)], authors(:david).reload.favorite_authors
+ end
+
private
# create dynamic Post models to allow different dependency options
def find_post_with_dependency(post_id, association, association_name, dependency)