mocking CanCan authorization while testing controllers with RSpec

不羁岁月 提交于 2019-12-04 14:11:57

When you're using load_and_authorize_resource in cancan, it only passes an instance of user to the authorize method when the action is update, show, edit or destroy(I think). When the action is index it passes the User class instead.

That's why your expectation inside should_authorize fails

You can see how cancan does the loading here:

https://github.com/ryanb/cancan/blob/master/lib/cancan/controller_resource.rb#L76

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!