title: Testing Login with minitest-rails
body: <p>I'm very new to minitest-rails.</p>
  
  <p>Currently, doing test for my login controller.</p>
  
  <p><strong>First</strong>, do I need to set <strong>encrypted password</strong> in my <strong>users fixtures</strong>?</p>
  
  <pre><code>admin:
   fullname: Administrator
   username: admin
   password_digest: $2a$10$RVjBGDtSlmOHCKvgUbqYCuBT1QFQ0NfU6b1WgwLOS3/PFDzwEG4bq
   status: true
   email: test@test.net
   role: admin
   last_updated_by: admin
  </code></pre>
  
  <p>here is my <strong>LoginModule</strong> codes:</p>
  
  <pre><code>def authenticate_current_user(username, password)
    User.find_by(username: username).try(:authenticate, password)
  end
  </code></pre>
  
  <p>here is my <strong>Login Controller</strong> codes (using <strong>POST</strong> method):</p>
  
  <pre><code>def authenticate_login
    user = authenticate_current_user(params[:username], params[:password])
     if user.status == true
       session[:username] = user.username
       session[:user_id] = user.id
       session[:role] = user.role
  
       flash.keep[:status] = "success"
       redirect_to "/home", :notice =&gt; "Hi #{user.username.capitalize}! you have successfully logged in."
     else
       flash.keep[:status] = "error"        
       redirect_to "/login", :notice =&gt; "Invalid Username or Password!"
     end
  end
  </code></pre>
  
  <p>Here is my <strong>LoginControllerTest</strong> codes:</p>
  
  <pre><code>test "should authenticate_login" do
      @user = users(:admin)
      # I tried
      post :authenticate_login, params: { username: @user.username, password: 'pwwadmin' } # Not working
  
      # and also
      post :authenticate_login, params: { session: {username: @user.username, password: 'pwwadmin'} } # Not working
  
      assert_not_nil(@user)
      assert_equal session[:username], @user.username
      assert_equal flash[:status], 'success'
      assert_response :success
  end
  </code></pre>
  
  <p><strong>Result:</strong>, always turns to <strong>else</strong> clause. It seems that I'm having trouble with the password?</p>
  
  <pre><code>   else
       flash.keep[:status] = "error"        
       redirect_to "/login", :notice =&gt; "Invalid Username or Password!"
     end
  </code></pre>
  
  <p><strong>Please help to fix my login test.</strong></p>