Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky spec #712

Merged
merged 2 commits into from
Aug 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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