From a74a6b8532f2b296245ac743bdcc05764882ab1f Mon Sep 17 00:00:00 2001 From: Ildar Kayumov Date: Sat, 10 Aug 2024 10:50:33 +0200 Subject: [PATCH 1/2] tests (Bullet::Detector::Association): remove Post created during single spec --- .../active_record/association_spec.rb | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/spec/integration/active_record/association_spec.rb b/spec/integration/active_record/association_spec.rb index c913c5a3..f4a19d25 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 From 11e91abbaa3abe7f66265cfe481ee683511946f6 Mon Sep 17 00:00:00 2001 From: Ildar Kayumov Date: Sat, 10 Aug 2024 11:11:30 +0200 Subject: [PATCH 2/2] tests (Bullet::Detector::Association): remove Documents created during specs --- .../active_record/association_spec.rb | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/spec/integration/active_record/association_spec.rb b/spec/integration/active_record/association_spec.rb index f4a19d25..2fc37851 100644 --- a/spec/integration/active_record/association_spec.rb +++ b/spec/integration/active_record/association_spec.rb @@ -694,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 @@ -705,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 @@ -715,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! @@ -726,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