我在测试环境中使用了binding.pry,但得到了一些非常奇怪的结果:
[4] pry(#<RentalItem>)> self.charged_amounts
=> [#<ChargedAmount id: 1, type_of_amount:"rental", charge_id:1, rental_item_id:1>, #<ChargedAmount id: 2, ...>]
[5] pry(#<RentalItem>)> self.charged_amounts.where(type_of_amount:"rental")
=> []
[6] pry(#<RentalItem>)> self.charged_amounts.where(charge_id:1)
=> []
[7] pry(#<RentalItem>)> self.charged_amounts.where(rental_item_id:1)
=> []试图理解并获得一些关于为什么会发生上述行为的想法。也就是说,给我一个调试的起点。
谢谢
发布于 2016-06-03 09:44:07
这是因为rails处理事务性fixture的方式。基本上,记录在两次测试之间被删除。你可以在这里阅读更多信息Transactional Fixtures in Rails
https://stackoverflow.com/questions/37604612
复制相似问题