比方说,我们有一个模型中的方法是模型方法本身应该调用“保存”吗?
- 需要在保存记录只叫
- 可以更新模型本身,因此该模型需要重新保存后记
如果“保存”呼叫发生在方法本身内部,如下面的代码
def result
save! if new_record?
# do some funky stuff here that may also change the model state
# ...
# And calculate the return value
search_result = "foo" # Let's say "foo" is the value we calculated
save! if changed?
search_result # return
end
或者应该外部观察者(th e控制器)负责根据需要调用保存?
以某种方式相关的问题:http://stackoverflow.com/questions/3125198/should-a-modifying-class-method-save-itself-or-be-explicity-called-after-the-meth – 2010-10-09 16:36:52
此演示文稿测试可能能够帮助您找出该模型上的界面变得奇怪的地方。 https://github.com/jimweirich/presentation_testing_why_dont_we_do_it_like_this/raw/master/pdf/testing.key.pdf如果您觉得在测试应用程序时必须打到分贝,那么可能有一些功能可以考虑到这将使架构更易于使用。从第pg开始。 69. – 2011-02-07 21:15:21
不知道它是如何与问题实际相关的,但是出色的表现 - 感谢分享! – 2011-02-09 06:08:18