我正在尝试将用户限制为执行特定操作的管理员。在下文中,当用户登录(不是管理员)时,它不应该从传入的哈希中访问操作。这是它工作的 RSpec 代码,但对传入的哈希有疑问:
{ "new" => "get",
"create" => "post",
"edit" => "get",
"update" => "put",
"destroy" => "delete" }.each do |action, method|
it "cannot access the #{action} action" do
sign_in(:user, user)
send(method, action.dup, :id => project.id)
response.should redirect_to(root_path)
flash[:alert].should eql("You must be an admin to do that.")
end
end
我想知道为什么这里使用字符串"new"
, "create"
, ... 而不是使用符号:new
, :create
?它与action.dup
以后的send
方法调用有关吗?
谢谢!