Stubbing Chained Methods with Rspec

后端 未结 5 1081
醉酒成梦
醉酒成梦 2021-02-05 22:06

I want to call a named_scope that will only return one record, but the named_scope returns an array, that\'s not a big deal as I can just chain it with .first:

M         


        
5条回答
  •  滥情空心
    2021-02-05 23:02

    I suppose this is in a controller spec?

    Your own suggestion should work fine. Another possibility is to move the named_scope call inside your model, to avoid the issue entirely. This would also be in line with the "fat models, thin controllers" advice.

提交回复
热议问题