Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby on Rails Tutorial section 10.4.2 test fail

After completing listing Listing 10.40 and running rspec /spec/controllers/users_controller_spec.rb, I got 1 failure for section (all other tests in 'destroy' section are passed)

describe "DELETE 'destroy'" do

  before(:each) do
    @user = Factory(:user)
  end

  describe "as a non-signed-in user" do
    it "should deny access" do
      delete :destroy, :id => @user
      response.should redirect_to(signin_path)
    end
  end
end

Here is the console output:

Failures:
  1) UsersController DELETE 'destroy' as a non-signed-in user should deny access
     Failure/Error: delete :destroy, :id => @user
     undefined method `admin?' for nil:NilClass
     # ./app/controllers/users_controller.rb:66:in `admin_user'
     # ./spec/controllers/users_controller_spec.rb:282:in `block (4 levels) in <top (required)>'

I can't figure out whether there is an error in the tutorial's code or I made a mistake somewhere.

like image 606
Artem Pakk Avatar asked Dec 19 '25 04:12

Artem Pakk


1 Answers

I believe that readers who run into this problem are simply missing the :destroy method in the :authenticate before filter introduced in Listing 10.11. (Note: I am the author of the book.)

like image 91
mhartl Avatar answered Dec 20 '25 21:12

mhartl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!