我正在尝试为使用 Devise 进行身份验证的 Rails 应用程序生成一个简单的宏。基本上我想确保当用户访问需要身份验证的页面时,他们会被重定向到登录页面。所以是这样的:
it_requires_authentication_for :index, :new, :create, :update
这里想要的结果应该是显而易见的。然而,我的问题是我想不出将每个操作映射到其适当的 http 方法(:get、:post 等...)的最佳方法
我从这个开始:
def it_should_require_authentication_for(*actions)
actions.each do |action|
it "should require authentication for #{action}" do
get action.to_sym
response.should redirect_to( new_user_session_path )
end
end
end
当然只有得到。有人可以告诉我如何为所有操作提供此宏吗?我假设我需要以某种方式测试特定方法的操作是否正确路由,但我只是不太确定。
任何帮助是极大的赞赏。