Skip to content

Commit

Permalink
Merge pull request #712 from ildarkayumov/fix-flaky-spec
Browse files Browse the repository at this point in the history
Fix flaky spec
  • Loading branch information
flyerhzm authored Aug 11, 2024
2 parents 9ea62db + 11e91ab commit 367b62d
Showing 1 changed file with 32 additions and 9 deletions.
41 changes: 32 additions & 9 deletions spec/integration/active_record/association_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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!
Expand All @@ -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

Expand Down

0 comments on commit 367b62d

Please sign in to comment.