【发布时间】:2012-05-03 21:27:53
【问题描述】:
我正在尝试将用户限制为执行特定操作的管理员。在下文中,当用户登录(不是管理员)时,它不应该从传入的哈希中访问操作。这是它工作的一段 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 之类的符号?是不是和后面的send方法调用中的action.dup有关系??
谢谢!
【问题讨论】:
-
为什么需要 dup 方法,没有它似乎可以工作?,然后可以使用符号
标签: rspec rspec2 rspec-rails