aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations
diff options
context:
space:
mode:
authorMurray Steele <muz@h-lame.com>2009-03-12 13:49:16 +0000
committerPratik Naik <pratiknaik@gmail.com>2009-03-12 13:49:16 +0000
commitdb26ace030f6704da6fc80bcc6cd00a2aee664ce (patch)
treee9f4a8c95527408fe936943e24d9a5bc36405bdb /activerecord/test/cases/associations
parent92dadf6d7927fde1482ba1d96d0916093bfb83ca (diff)
downloadrails-db26ace030f6704da6fc80bcc6cd00a2aee664ce.tar.gz
rails-db26ace030f6704da6fc80bcc6cd00a2aee664ce.tar.bz2
rails-db26ace030f6704da6fc80bcc6cd00a2aee664ce.zip
Ensure NoMethodError isn't raised when some of the nested eager loaded associations are empty [#1696 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'activerecord/test/cases/associations')
-rw-r--r--activerecord/test/cases/associations/eager_load_nested_include_test.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/eager_load_nested_include_test.rb b/activerecord/test/cases/associations/eager_load_nested_include_test.rb
index 12dec5ccd1..1b2e0fc11e 100644
--- a/activerecord/test/cases/associations/eager_load_nested_include_test.rb
+++ b/activerecord/test/cases/associations/eager_load_nested_include_test.rb
@@ -1,4 +1,9 @@
require 'cases/helper'
+require 'models/author'
+require 'models/post'
+require 'models/comment'
+require 'models/category'
+require 'models/categorization'
module Remembered
def self.included(base)
@@ -99,3 +104,27 @@ class EagerLoadPolyAssocsTest < ActiveRecord::TestCase
end
end
end
+
+class EagerLoadNestedIncludeWithMissingDataTest < ActiveRecord::TestCase
+ def setup
+ @davey_mcdave = Author.create(:name => 'Davey McDave')
+ @first_post = @davey_mcdave.posts.create(:title => 'Davey Speaks', :body => 'Expressive wordage')
+ @first_comment = @first_post.comments.create(:body => 'Inflamatory doublespeak')
+ @first_categorization = @davey_mcdave.categorizations.create(:category => Category.first, :post => @first_post)
+ end
+
+ def teardown
+ @davey_mcdave.destroy
+ @first_post.destroy
+ @first_comment.destroy
+ @first_categorization.destroy
+ end
+
+ def test_missing_data_in_a_nested_include_should_not_cause_errors_when_constructing_objects
+ assert_nothing_raised do
+ # @davey_mcdave doesn't have any author_favorites
+ includes = {:posts => :comments, :categorizations => :category, :author_favorites => :favorite_author }
+ Author.all :include => includes, :conditions => {:authors => {:name => @davey_mcdave.name}}, :order => 'categories.name'
+ end
+ end
+end \ No newline at end of file