Hartl Rails Tutorial Ch9, "test_should_redirect_destroy_when_not_logged_in" : Working through Hartl's tutorial, in Chapter 9, Listing 9.56 produces the following error, showing 'admin?' as an undefined method. 

I've checked (and rechecked) the 2 sections of code that have been revised since the last green test. Stumped.   

     ERROR["test_should_redirect_destroy_when_not_logged_in", UsersControllerTest, 2016-02-26 21:29:01 -0500]
     test_should_redirect_destroy_when_not_logged_in#UsersControllerTest (1456540141.41s)
    NoMethodError:         NoMethodError: undefined method `admin?' for nil:NilClass
                app/controllers/users_controller.rb:73:in `admin_user'
                test/controllers/users_controller_test.rb:48:in `block (2 levels) in <class:UsersControllerTest>'
                test/controllers/users_controller_test.rb:47:in `block in <class:UsersControllerTest>'
            app/controllers/users_controller.rb:73:in `admin_user'
            test/controllers/users_controller_test.rb:48:in `block (2 levels) in <class:UsersControllerTest>'
            test/controllers/users_controller_test.rb:47:in `block in <class:UsersControllerTest>'
    
      39/39: [==========================================================] 100% Time: 00:00:00, Time: 00:00:00
    
    Finished in 0.97767s
    39 tests, 152 assertions, 0 failures, 1 errors, 0 skips

Note that the admin field was added to the database during a migration, which I understand *should* automatically produce a boolean admin? method

    class AddAdminToUsers < ActiveRecord::Migration
      def change
        add_column :users, :admin, :boolean, default: false
      end
    end
     

users_controller_test.rb is where the problem apparently resides, specifically in the lines:

    test "should redirect destroy when not logged in" do
      assert_no_difference 'User.count' do
      delete :destroy, id: @user

...while the complete file looks like this:

    require 'test_helper'
    
    class UsersControllerTest < ActionController::TestCase
    
      def setup
        @user       = users(:michael)
        @other_user = users(:archer)
      end
      
      test "should redirect index when not logged in" do
        get :index
        assert_redirected_to login_url
      end
    
      test "should get new" do
        get :new
        assert_response :success
      end
    
      test "should redirect edit when not logged in" do
        get :edit, id: @user
        assert_not flash.empty?
        assert_redirected_to login_url
      end
      
      test "should redirect to update when not logged in" do
        patch :update, id: @user, user: { name: @user.name, email: @user.email }
        assert_not flash.empty?
        assert_redirected_to login_url
      end
      
      test "should redirect edit when logged in as wrong user" do
        log_in_as(@other_user)
        get :edit, id: @user
        assert flash.empty?
        assert_redirected_to root_url
      end
      
      test "should redirect update when logged in as wrong user" do
        log_in_as(@other_user)
        patch :update, id: @user, user: {name: @user.name, email: @user.email }
        assert flash.empty?
        assert_redirected_to root_url
      end
      
      test "should redirect destroy when not logged in" do
        assert_no_difference 'User.count' do
          delete :destroy, id: @user
        end
        assert_redirected_to login_url
      end
    
      test "should redirect destroy when logged in as a non-admin" do
        log_in_as(@other_user)
        assert_no_difference 'User.count' do
          delete :destroy, id: @user
        end
        assert_redirected_to root_url
      end
    end

and here's the contents of users.yaml

    # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

    michael:
      name: Michael Example
      email: michael@example.com
      password_digest: <%= User.digest('password') %>
      admin: true
      
    archer:
      name: Sterling Archer
      email: duchess@example.gov
      password_digest: <%= User.digest('password') %>
      
    lana:
      name: Lana Kane
      email: hands@example.gov
      password_digest: <%= User.digest('password') %>
    
    mallory:
      name: Mallory Archer
      email: boss@example.gov
      password_digest: <%= User.digest('password') %>
    
    <% 30.times do |n| %>
    user_<%= n %>:
      name:  <%= "User #{n}" %>
      email: <%= "user-#{n}@example.com" %>
      password_digest: <%= User.digest('password') %>
    <% end %>
