开发者

Chapter 10.13, two unit tests fail without explanation

开发者 https://www.devze.com 2023-01-26 15:11 出处:网络
I\'ve seen this problem listed on getsatisfaction.com, but don\'t understand the workaround. http://getsatisfaction.com/railstutorial/topics/listing_10_15_causes_user_validation_failure_running_rspe

I've seen this problem listed on getsatisfaction.com, but don't understand the workaround.

http://getsatisfaction.com/railstutorial/topics/listing_10_15_causes_user_validation_failure_running_rspec

This code is failing for some reason in users_controller_spec.rb and maybe it's because the factory isn't creating both an improper user and proper user to simulate the improper user accessing the proper user's edit page: (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

I get the following errors running 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) User开发者_开发百科sController 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)>'


Well, it gives an explanation: it's trying to build routes without any id provided. Are you sure that @user contains an actual user?

0

精彩评论

暂无评论...
验证码 换一张
取 消