我已经在getsatisfaction.com上看到了这个问题,但是我不明白这个问题。
此代码由于某种原因在users_controller_spec.rb中失败,也许是因为工厂没有同时创建一个不正确的用户和正确的用户来模拟访问正确用户编辑页面的不正当用户: (10.13)
describe "for signed-in users" do
before(:each) do
wrong_user = Factory(:user, :email => "user@example.net")
test_sign_in(wrong_user)
end
it "should require matching users for 'edit'" do
get :edit, :id => @user
response.should redirect_to(root_path)
end
it "should require matching users for 'update'" do
put :update, :id => @user, :user => {}
response.should redirect_to(root_path)
end
我在运行rspec时遇到以下错误:
Failures:
1) UsersController authentication of edit/update pages for signed-in users should require matching users for 'edit'
Failure/Error: get :edit, :id => @user
No route matches {:id=>nil, :controller=>"users", :action=>"edit"}
# ./spec/controllers/users_controller_spec.rb:223:in `block (4 levels) in <top (required)>'
2) UsersController authentication of edit/update pages for signed-in users should require matching users for 'update'
Failure/Error: put :update, :id => @user, :user => {}
No route matches {:id=>nil, :user=>{}, :controller=>"users", :action=>"update"}
# ./spec/controllers/users_controller_spec.rb:228:in `block (4 levels) in <top (required)>'
答案 0 :(得分:0)
嗯,给出一个解释:它试图在没有提供任何id
的情况下构建路由。您确定@user
包含实际用户吗?