title: Rails 4: Sessions - undefined method `current_user'
body: <p>I am following along this tutorial's authentication process:</p>
  
  <p><a href="http://larsgebhardt.de/user-authentication-with-ruby-on-rails-rspec-and-capybara/" rel="nofollow noreferrer">http://larsgebhardt.de/user-authentication-with-ruby-on-rails-rspec-and-capybara/</a></p>
  
  <p>Since the tutorial is based off Rails 3, according to the last commenter in the article above, there are only a few modifications needed to make the tutorial compatible with Rails 4. I made those changes but still continue to chase my tail with issues. I have posted questions 2 other times on Stack Overflow and although I'm getting answers that 'fix' the current issue at hand, I'm afraid I might be straying away from the tutorial's approach of authentication from scratch - further breaking the tests which is causing a domino effect of issues.</p>
  
  <p>For a bit of history, here is the last two questions in chronological order..</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/29183573/rspec-email-spec-issue">Rspec email_spec issue</a></li>
  <li><a href="https://stackoverflow.com/questions/29201804/rspec-capybara-uninitialized-constant-sessioncontroller">Rspec &amp; Capybara: uninitialized constant SessionController</a></li>
  </ul>
  
  <p>So here's the failure I have now..</p>
  
  <pre><code>  5) User Management User log out
       Failure/Error: activate(@writer)
       ActionView::Template::Error:
         undefined method `current_user' for #&lt;SessionsController:0x007fd2029c8d68&gt;
  </code></pre>
  
  <p><strong>users_spec.rb</strong>..</p>
  
  <pre><code>feature 'User Management' do
  
      background do
        @writer = create(:user, :writer)
      end
  
  scenario 'User log out' do
    activate(@writer)
    login(@writer)
    logout(@writer)
    expect(page).to have_content "Successfully logged out."
  end
  </code></pre>
  
  <p>The method exists in my <strong>profiles_controller.rb</strong> - which is similar to the tutorial's <em>offices_controller.rb</em></p>
  
  <pre><code>class ProfilesController &lt; ApplicationController
  
  
    def show
      auth_required
      access_only_with_roles("writer", "admin")
    end
  
    def current_user
      @current_user ||=  User.find(session[:user_id]) if session[:user_id]
    end
  end
  </code></pre>
  
  <p>This is the <strong>_header.html.erb</strong> file with the Log Out link code. </p>
  
  <pre><code>    &lt;a href="#"&gt;&lt;%= link_to "Sign Up", new_user_path %&gt;&lt;/a&gt;
      &lt;a href="#"&gt;&lt;%= link_to "Log In", new_session_path %&gt;&lt;/a&gt;
      &lt;a href="#"&gt;&lt;%= link_to "Log Out", session_path(current_user), method: :delete %&gt;&lt;/a&gt;
  </code></pre>
  
  <p>My <strong>routes.rb</strong>..</p>
  
  <pre><code>Rails.application.routes.draw do
    get 'profiles/show'
  
    get 'sessions/new'
  
    get 'users/new'
  
    # The priority is based upon order of creation: first created -&gt; highest priority.
    # See how all your routes lay out with "rake routes".
  
    # You can have the root of your site routed with "root"
   root 'sessions#new'
  
    resources :posts do
      resources :comments
  end
  
  
    resources :sessions
    resources :users
    resources :profile
  
    get "activate/:code" =&gt; "users#activate", :as =&gt; "activate"
  </code></pre>
  
  <p>..and <strong>rake routes</strong></p>
  
  <pre><code>    Prefix Verb   URI Pattern                                 Controller#Action
      profiles_show GET    /profiles/show(.:format)                    profiles#show
       sessions_new GET    /sessions/new(.:format)                     sessions#new
          users_new GET    /users/new(.:format)                        users#new
               root GET    /                                           sessions#new
      post_comments GET    /posts/:post_id/comments(.:format)          comments#index
                    POST   /posts/:post_id/comments(.:format)          comments#create
   new_post_comment GET    /posts/:post_id/comments/new(.:format)      comments#new
  edit_post_comment GET    /posts/:post_id/comments/:id/edit(.:format) comments#edit
       post_comment GET    /posts/:post_id/comments/:id(.:format)      comments#show
                    PATCH  /posts/:post_id/comments/:id(.:format)      comments#update
                    PUT    /posts/:post_id/comments/:id(.:format)      comments#update
                    DELETE /posts/:post_id/comments/:id(.:format)      comments#destroy
              posts GET    /posts(.:format)                            posts#index
                    POST   /posts(.:format)                            posts#create
           new_post GET    /posts/new(.:format)                        posts#new
          edit_post GET    /posts/:id/edit(.:format)                   posts#edit
               post GET    /posts/:id(.:format)                        posts#show
                    PATCH  /posts/:id(.:format)                        posts#update
                    PUT    /posts/:id(.:format)                        posts#update
                    DELETE /posts/:id(.:format)                        posts#destroy
           sessions GET    /sessions(.:format)                         sessions#index
                    POST   /sessions(.:format)                         sessions#create
        new_session GET    /sessions/new(.:format)                     sessions#new
       edit_session GET    /sessions/:id/edit(.:format)                sessions#edit
            session GET    /sessions/:id(.:format)                     sessions#show
                    PATCH  /sessions/:id(.:format)                     sessions#update
                    PUT    /sessions/:id(.:format)                     sessions#update
                    DELETE /sessions/:id(.:format)                     sessions#destroy
              users GET    /users(.:format)                            users#index
                    POST   /users(.:format)                            users#create
           new_user GET    /users/new(.:format)                        users#new
          edit_user GET    /users/:id/edit(.:format)                   users#edit
               user GET    /users/:id(.:format)                        users#show
                    PATCH  /users/:id(.:format)                        users#update
                    PUT    /users/:id(.:format)                        users#update
                    DELETE /users/:id(.:format)                        users#destroy
      profile_index GET    /profile(.:format)                          profile#index
                    POST   /profile(.:format)                          profile#create
        new_profile GET    /profile/new(.:format)                      profile#new
       edit_profile GET    /profile/:id/edit(.:format)                 profile#edit
            profile GET    /profile/:id(.:format)                      profile#show
                    PATCH  /profile/:id(.:format)                      profile#update
                    PUT    /profile/:id(.:format)                      profile#update
                    DELETE /profile/:id(.:format)                      profile#destroy
           activate GET    /activate/:code(.:format)                   users#activate
  </code></pre>
  
  <p>I would love to figure this out once and for all. It appeared to be a great tutorial. If I figure out the changes then I plan to post them in the comment section of the article for anyone else who plans to use it. </p>