Skip to content

Commit

Permalink
accurate test assertions for association spec
Browse files Browse the repository at this point in the history
  • Loading branch information
flyerhzm committed May 6, 2012
1 parent d3c367b commit fd4e7cd
Showing 1 changed file with 27 additions and 25 deletions.
52 changes: 27 additions & 25 deletions spec/integration/association_spec.rb
Expand Up @@ -145,14 +145,17 @@
end

context "category => posts => comments" do
it "should detect preload with category => posts => comments" do
Category.includes({:posts => :comments}).each do |category|
it "should detect non preload category => posts => comments" do
Category.all.each do |category|
category.posts.each do |post|
post.comments.collect(&:name)
post.comments.map(&:name)
end
end
# Bullet::Detector::Association.should_not be_has_unpreload_associations
Bullet::Detector::Association.should be_completely_preloading_associations
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
Bullet::Detector::Association.should_not be_has_unused_preload_associations

Bullet::Detector::Association.should be_detecting_unpreloaded_association_for(Category, :posts)
Bullet::Detector::Association.should be_detecting_unpreloaded_association_for(Post, :comments)
end

it "should detect preload category => posts, but no post => comments" do
Expand All @@ -161,42 +164,41 @@
post.comments.collect(&:name)
end
end
# Bullet::Detector::Association.should be_has_unpreload_associations
Bullet::Detector::Association.should_not be_completely_preloading_associations
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
Bullet::Detector::Association.should_not be_has_unused_preload_associations

Bullet::Detector::Association.should_not be_detecting_unpreloaded_association_for(Category, :posts)
Bullet::Detector::Association.should be_detecting_unpreloaded_association_for(Post, :comments)
end

it "should detect no preload category => posts => comments" do
Category.all.each do |category|
it "should detect preload with category => posts => comments" do
Category.includes({:posts => :comments}).each do |category|
category.posts.each do |post|
post.comments.collect(&:name)
post.comments.map(&:name)
end
end
# Bullet::Detector::Association.should be_has_unpreload_associations
Bullet::Detector::Association.should_not be_completely_preloading_associations
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
Bullet::Detector::Association.should_not be_has_unused_preload_associations

Bullet::Detector::Association.should be_completely_preloading_associations
end

it "should detect unused preload with category => posts => comments" do
Category.includes({:posts => :comments}).collect(&:name)
Category.includes({:posts => :comments}).map(&:name)
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
Bullet::Detector::Association.should be_has_unused_preload_associations
Bullet::Detector::Association.should be_unused_preload_associations_for(Post, :comments)

Bullet::Detector::Association.should be_completely_preloading_associations
end

it "should detect unused preload with post => commnets, no category => posts" do
Category.includes({:posts => :comments}).each do |category|
category.posts.collect(&:name)
category.posts.map(&:name)
end
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
Bullet::Detector::Association.should be_has_unused_preload_associations
end
Bullet::Detector::Association.should be_unused_preload_associations_for(Post, :comments)

it "should no detect preload with category => posts => comments" do
Category.all.each do |category|
category.posts.each do |post|
post.comments.collect(&:name)
end
end
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
Bullet::Detector::Association.should_not be_has_unused_preload_associations
Bullet::Detector::Association.should be_completely_preloading_associations
end
end

Expand Down

0 comments on commit fd4e7cd

Please sign in to comment.