{ "new" => "get",
"create" => "post",
"edit" => "get",
"update" => "put",
"destroy" => "delete" }.each do |action, method|
it "不能存取 #{action} 动作" do
sign_in(:user, user)
send(method, action.dup, :id => project.id)
response.should redirect_to(root_path)
flash[:alert].should eql("亲,你必须是管理员才能这么做哦!")
end
end
"new"=>"get" ... 这里不用符号用字串的原因,貌似是动作变量是 Ruby 1.9.2 的 Frozen 字串,所以需要复制这个对象,这样 Rails 才会强迫它的编码为 UTF-8。
不知道对不对,楼下请指导。