title: Rails Tutorial Ch. 9 Exercise 6: Expected response to be a <redirect>, but was <200>
body: <p>I am trying to write tests and application code to redirect users who are already signed-in to the root_path if they try to CREATE a user or visit the NEW user path.</p>
  
  <p>Here are the tests I have written in user_pages_spec.rb:</p>
  
  <pre><code>describe "for signed in users" do
        let(:user) { FactoryGirl.create(:user) }
        before { sign_in user }
  
        describe "using a 'new' action" do
          before { get new_user_path }
          specify { response.should redirect_to(root_path) }
        end
  
        describe "using a 'create' action" do
          before { post users_path }
          specify { response.should redirect_to(root_path) }
        end         
    end 
  </code></pre>
  
  <p>UsersController:</p>
  
  <pre><code>class UsersController &lt; ApplicationController
    before_action :unsigned_in_user, only: [:create, :new]
  
    def new
      @user = User.new
    end
  
    def create
       @user = User.new(user_params)
       if @user.save
        sign_in @user
            flash[:success] = "Welcome to the Sample App!"
            redirect_to @user
       else
            render 'new'
       end
    end
  
    private
      # Before filters
  
      def user_params
        params.require(:user).permit(:name, :email, :password,
                                 :password_confirmation)
      end
  
      def unsigned_in_user
        puts signed_in?
        redirect_to root_url, notice: "You are already signed in." unless !signed_in?
      end
  end
  </code></pre>
  
  <p>The <code>puts signed_in?</code> returns false.  I am assuming this is the problem because I would expect it to return true.  Here are the errors after running the tests using rspec.  Any help is appreciated.</p>
  
  <pre><code>Failures:
  
    1) User pages for signed in users using a 'create' action 
       Failure/Error: before { post users_path }
       ActionController::ParameterMissing:
         param not found: user
       # ./app/controllers/users_controller.rb:52:in `user_params'
       # ./app/controllers/users_controller.rb:20:in `create'
       # ./spec/requests/user_pages_spec.rb:162:in `block (4 levels) in &lt;top (required)&gt;'
  
    2) User pages for signed in users using a 'new' action 
       Failure/Error: specify { response.should redirect_to(root_path) }
         Expected response to be a &lt;redirect&gt;, but was &lt;200&gt;
       # ./spec/requests/user_pages_spec.rb:158:in `block (4 levels) in &lt;top (required)&gt;'
  </code></pre>
  
  <p>Within the sessions_helper.rb file:</p>
  
  <pre><code>def signed_in?
      !current_user.nil?
  end
  </code></pre>
  
  <p>In spec/support/utilities.rb:</p>
  
  <pre><code>def sign_in(user, options={})
    if options[:no_capybara]
      # Sign in when not using Capybara.
      remember_token = User.new_remember_token
      cookies[:remember_token] = remember_token
      user.update_attribute(:remember_token, User.encrypt(remember_token))
    else
      visit signin_path
      fill_in "Email",    with: user.email
      fill_in "Password", with: user.password
      click_button "Sign in"
    end
  end
  </code></pre>