aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/associations_go_eager_test.rb
diff options
context:
space:
mode:
authorJamis Buck <jamis@37signals.com>2005-06-10 13:54:58 +0000
committerJamis Buck <jamis@37signals.com>2005-06-10 13:54:58 +0000
commit7f9ffb2ebf1a0230368f54a6372cb7196c90177e (patch)
tree6cfa7b09101c91f9d30a656c1796d77b12efe507 /activerecord/test/associations_go_eager_test.rb
parentf6ec9e3d66a8f5acd5eb79e3d1f77a2d1e1b5d31 (diff)
downloadrails-7f9ffb2ebf1a0230368f54a6372cb7196c90177e.tar.gz
rails-7f9ffb2ebf1a0230368f54a6372cb7196c90177e.tar.bz2
rails-7f9ffb2ebf1a0230368f54a6372cb7196c90177e.zip
Eager loading of dependent has_one associations won't delete the association #1212. Also, starting to refactor the tests to make them speedier, with optional support for transactional fixtures.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1398 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test/associations_go_eager_test.rb')
-rw-r--r--activerecord/test/associations_go_eager_test.rb35
1 files changed, 22 insertions, 13 deletions
diff --git a/activerecord/test/associations_go_eager_test.rb b/activerecord/test/associations_go_eager_test.rb
index a3e819e028..3aeba9031e 100644
--- a/activerecord/test/associations_go_eager_test.rb
+++ b/activerecord/test/associations_go_eager_test.rb
@@ -3,47 +3,49 @@ require 'fixtures/post'
require 'fixtures/comment'
require 'fixtures/author'
require 'fixtures/category'
+require 'fixtures/company'
class EagerAssociationTest < Test::Unit::TestCase
- fixtures :posts, :comments, :authors, :categories, :categories_posts
+ fixtures :posts, :comments, :authors, :categories, :categories_posts,
+ :companies, :accounts
def test_loading_with_one_association
posts = Post.find(:all, :include => :comments)
assert_equal 2, posts.first.comments.size
- assert posts.first.comments.include?(@greetings)
+ assert posts.first.comments.include?(comments(:greetings))
post = Post.find(:first, :include => :comments, :conditions => "posts.title = 'Welcome to the weblog'")
assert_equal 2, post.comments.size
- assert post.comments.include?(@greetings)
+ assert post.comments.include?(comments(:greetings))
end
def test_with_ordering
posts = Post.find(:all, :include => :comments, :order => "posts.id DESC")
- assert_equal @authorless, posts[0]
- assert_equal @thinking, posts[1]
- assert_equal @welcome, posts[2]
+ assert_equal posts(:authorless), posts[0]
+ assert_equal posts(:thinking), posts[1]
+ assert_equal posts(:welcome), posts[2]
end
def test_loading_with_multiple_associations
posts = Post.find(:all, :include => [ :comments, :author, :categories ], :order => "posts.id")
assert_equal 2, posts.first.comments.size
assert_equal 2, posts.first.categories.size
- assert posts.first.comments.include?(@greetings)
+ assert posts.first.comments.include?(comments(:greetings))
end
def test_loading_from_an_association
- posts = @david.posts.find(:all, :include => :comments, :order => "posts.id")
+ posts = authors(:david).posts.find(:all, :include => :comments, :order => "posts.id")
assert_equal 2, posts.first.comments.size
end
def test_loading_with_no_associations
- assert_nil Post.find(@authorless.id, :include => :author).author
+ assert_nil Post.find(posts(:authorless).id, :include => :author).author
end
def test_eager_association_loading_with_belongs_to
comments = Comment.find(:all, :include => :post)
- assert_equal @welcome.title, comments.first.post.title
- assert_equal @thinking.title, comments.last.post.title
+ assert_equal posts(:welcome).title, comments.first.post.title
+ assert_equal posts(:thinking).title, comments.last.post.title
end
def test_eager_association_loading_with_habtm
@@ -51,12 +53,19 @@ class EagerAssociationTest < Test::Unit::TestCase
assert_equal 2, posts[0].categories.size
assert_equal 1, posts[1].categories.size
assert_equal 0, posts[2].categories.size
- assert posts[0].categories.include?(@technology)
- assert posts[1].categories.include?(@general)
+ assert posts[0].categories.include?(categories(:technology))
+ assert posts[1].categories.include?(categories(:general))
end
def test_eager_with_inheritance
posts = SpecialPost.find(:all, :include => [ :comments ])
end
+
+ def test_eager_with_has_one_dependent_does_not_destroy_dependent
+ assert_not_nil companies(:first_firm).account
+ f = Firm.find(:first, :include => :account,
+ :conditions => ["companies.name = ?", "37signals"])
+ assert_not_nil companies(:first_firm, :reload).account
+ end
end