如果我有一个Desive model用户,其中只有那些角色为:admin的用户才允许查看某个url,我如何编写RSpec集成测试来判断该url的状态是否返回200?
def login(user)
post user_session_path, :email => user.email, :password => 'password'
end
这个问题的答案是假的:Stubbing authentication in request spec,但我一辈子都无法让它与Desive一起工作.CanCan在判断能力时接收到一个nil用户,当然,该能力没有正确的权限.
集成规范中没有对控制器的访问权限,所以我不能对当前的用户进行存根,但我想这样做.
describe "GET /users" do
it "should be able to get" do
clear_users_and_add_admin #does what it says...
login(admin)
get users_path
response.status.should be(200)
end
end
NOTE!!!:自从提出这个问题以来,所有这些都发生了变化.目前最好的方法是:http://github.com/plataformatec/devise/wiki/How-To:-Test-with-Capybara