diff --git a/spec/integration/active_record/association_spec.rb b/spec/integration/active_record/association_spec.rb index c913c5a3..2fc37851 100644 --- a/spec/integration/active_record/association_spec.rb +++ b/spec/integration/active_record/association_spec.rb @@ -348,15 +348,23 @@ expect(Bullet::Detector::Association).to be_completely_preloading_associations end - it 'should not detect newly assigned object in an after_save' do - new_post = Post.new(category: Category.first) + context 'in an after_save' do + around do |example| + new_post = Post.new(category: Category.first) + new_post.trigger_after_save = true + new_post.save! - new_post.trigger_after_save = true - new_post.save! - Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations - expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations + example.run - expect(Bullet::Detector::Association).to be_completely_preloading_associations + new_post.destroy + end + + it 'should not detect newly assigned object' do + Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations + expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations + + expect(Bullet::Detector::Association).to be_completely_preloading_associations + end end end @@ -686,7 +694,7 @@ describe Bullet::Detector::Association, 'query immediately after creation' do context 'with save' do context 'document => children' do - it 'should not detect non preload associations' do + around do |example| document1 = Document.new document1.children.build document1.save @@ -697,7 +705,15 @@ document1.children.each.first + example.run + + document1.children.destroy_all + document1.destroy + end + + it 'should not detect non preload associations' do Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations + expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations expect(Bullet::Detector::Association).to be_completely_preloading_associations @@ -707,7 +723,7 @@ context 'with save!' do context 'document => children' do - it 'should not detect non preload associations' do + around do |example| document1 = Document.new document1.children.build document1.save! @@ -718,6 +734,13 @@ document1.children.each.first + example.run + + document1.children.destroy_all + document1.destroy + end + + it 'should not detect non preload associations' do Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations