工厂女孩& Rails:我们可以关闭包装每个测试的数据库事务吗?
当我测试应用程序中的一些线程功能时,我遇到了数据库锁定的问题 - 数据库锁定在一个线程上,然后所有其他线程都死锁。由于我的代码中没有显式事务,我不能只是手动保护和释放。
我在某处读到,TestCase 中的固定装置利用隐式(隐式到我的代码)事务来清理测试之间的数据库,但我找不到任何地方是否这对于 Factory Girl 来说也是如此。
有谁知道这是否属实,如果是,有没有办法针对特定测试(而不是所有测试)关闭它?
提前致谢!
I've got this issue with database locking when I'm testing some threading features I've got in my application--the database locks on one thread and then all the other threads deadlock on that. As there's no explicit transaction in my code I can't just guard and release manually.
I read somewhere that fixtures in TestCase leverage implicit (implicit to MY code) transactions to clean out the database between tests, but I can't find anywhere if this is true for Factory Girl as well.
Does anyone know if it is true and if so, is there a way to turn it off for specific tests, but not all of the tests?
thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
FactoryGirl 只需获取您的模型,设置属性,然后在该模型上调用#save。我认为你只需要改变一个设置。使用 RSpec,您的 spec_helper.rb 文件中应该有一行:
此配置被发送到 Rails 测试配置。然后在 #setup_fixtures< 中使用它/a> 方法。
Rails 文档事务固定装置
华泰
FactoryGirl just takes your model, sets the attributes, and calls #save on that model. I think you just need to change a setting. With RSpec, you should have a line in your spec_helper.rb file:
This config is sent to the Rails testing config. This is then used in the #setup_fixtures method.
The documentation on Rails transactional fixtures
HTH