tvi*_*ira 10 ruby rspec ruby-on-rails
我正试图标记N + 1并在代码中放置我可以使用bullet gem添加计数器缓存.但是手动完成所有操作来检查N + 1查询,看起来非常痛苦,所以我尝试使用Bullet和Rspec,使用他们推荐的设置步骤:
# 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
Run Code Online (Sandbox Code Playgroud)
但是当我运行规范时,似乎在规范本身而不是应用程序中标记N + 1个查询.你知道是否有可能达到我的目的吗?
这实际上是 gem 中的一个错误,请关注这里的问题,评论并投票以获得更快的解决方案: https: //github.com/flyerhzm/bullet/issues/407#issuecomment-437672707