spec/goldiloader/goldiloader_spec.rb in goldiloader-0.0.10 vs spec/goldiloader/goldiloader_spec.rb in goldiloader-0.0.11
- old
+ new
@@ -730,10 +730,21 @@
posts.drop(1).each do |blog|
expect(blog.association(:blog_without_auto_include)).to_not be_loaded
end
end
+ it "doesn't auto eager load has_and_belongs_to_many associations" do
+ posts = Post.all.to_a
+
+ # Force the first post's tags to load
+ posts.first.tags_without_auto_include.to_a
+
+ posts.drop(1).each do |post|
+ expect(post.association(:tags_without_auto_include)).to_not be_loaded
+ end
+ end
+
it "still auto eager loads nested associations" do
posts = Post.order(:title).to_a
# Force the first post's blog to load
blog = posts.first.blog_without_auto_include
@@ -747,9 +758,30 @@
expect(post.association(:tags)).to be_loaded
end
other_blog.posts.each do |post|
expect(post.association(:tags)).to_not be_loaded
+ end
+ end
+ end
+
+ describe "CollectionProxy#exists?" do
+ it "returns true for collections with values" do
+ expect(parent_tag1.children).to exist
+ end
+
+ it "returns false for collections without values" do
+ expect(child_tag1.children).not_to exist
+ end
+
+ if Goldiloader::Compatibility::RAILS_3
+ # Make sure we mimic the broken behavior of Rails 3
+ it "returns true for new models with empty associations" do
+ expect(Tag.new.children).to exist
+ end
+ else
+ it "returns false for new models with empty associations" do
+ expect(Tag.new.children).not_to exist
end
end
end
end