是否应该在一行上验证多个属性?
使用我使用的较旧的 Shoulda 插件,我曾经能够执行如下操作:
should_have_many :posts, :authors, :comments
升级我的 Shoulda 版本后,我必须将其更改为如下所示:
should have_many :posts
should have_many :authors
should have_many :comments
我尝试将其全部放在一行上,所以它是只是,
should have_many :posts, :authors, :comments
但这不起作用。有没有办法把它弄干一点?
我正在使用应该2.11.3
With the older Shoulda plugin I was using, I used to be able to do something like the following:
should_have_many :posts, :authors, :comments
After upgrading my version of Shoulda, I had to change it to something like this:
should have_many :posts
should have_many :authors
should have_many :comments
I've tried putting it all on one line so it's just
should have_many :posts, :authors, :comments
but that's not working. Is there anyway to DRY this up a little?
I'm using Shoulda 2.11.3
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试:
这将作为三个单独的测试显示在结果中。
我使用 Rspec,所以上面是 Rspec 格式,但我认为类似的方法应该适用于 Test::Unit。
我不确定这是否能为你节省那么多,但如果你有很多相同类型的关系,它会变得更有价值。也许它对
allow_mass_assignment_of
更有用。You could try:
This will show up in the results as three separate tests.
I use Rspec, so above is Rspec formatting, but I assume a similar approach should work with Test::Unit.
I'm not sure if this is going to save you all that much but if you have many of the same type of relationship it would become more valuable. Perhaps it is of better use for
allow_mass_assignment_of
.