Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flag N+1 queries with bullet in Rspec

I'm trying to flag N+1 and places in the code where I can add counter caches, using the bullet gem. But doing everything manually to check N+1 queries, seems very painfully, so I tried to use Bullet with Rspec, using the setup steps they recommend:

# config/environments/test.rb
config.after_initialize do
  Bullet.enable = true
  Bullet.bullet_logger = true
  Bullet.raise = true # raise an error if n+1 query occurs
end

# spec/spec_helper.rb
if Bullet.enable?
  config.before(:each) do
    Bullet.start_request
  end

  config.after(:each) do
    Bullet.perform_out_of_channel_notifications if Bullet.notification?
    Bullet.end_request
  end
end

But when I run the specs, seems to flag N+1 queries within specs itself rather than the app. Do you know if it's possible to achieve what I want?

like image 313
tvieira Avatar asked Sep 05 '16 15:09

tvieira


1 Answers

this is actually a bug in the gem, please follow the issue here, comment and upvote for a faster resolution: https://github.com/flyerhzm/bullet/issues/407#issuecomment-437672707

like image 184
fabriciofreitag Avatar answered Sep 20 '22 16:09

fabriciofreitag