0
我看到這個問題列在getsatisfaction.com上,但不明白解決方法。第10.13章,兩個單元測試失敗,沒有解釋
此代碼失敗由於某種原因在users_controller_spec.rb,也許這是因爲工廠沒有既創造一個不正確的用戶和適當的用戶來模擬用戶不當訪問正確的用戶編輯頁面: (10.13)
describe "for signed-in users" do
before(:each) do
wrong_user = Factory(:user, :email => "[email protected]")
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)>'
我想我設法解決這個問題。在user_controller_spec.rb – ajcbowhill 2010-11-21 16:32:01
中的「編輯/更新頁面的認證」部分下,未將單元測試塊放置爲「登錄用戶」的單元測試塊是我的錯@不是爲這對測試創建用戶。感謝您的回覆! – ajcbowhill 2010-11-21 16:32:35