title: Ruby on Rails Tutorial - test, reset password
body: <p>I have problem with understanding one code in Michael Hartl's tutorial.</p>
  
  <p>In <code>PasswordResetsTest</code> class, in test <code>password resets</code> we took our user from fixtures, we posted to <code>password_resets_path</code> with right mail and we asserted that <code>@user.reset_digest</code> doesn't equal <code>@user.reload.reset_digest</code>.<br>
  Later, Michael said we need to use assigns method to be able to patch to <code>password_reset_path</code>. He said it's because our user from fixtures doesn't have <code>reset_token</code>, because it is created only in create_reset_digest method.<br>
  I understand it, but I don't get one thing - why <code>assert_not_equal</code> with pre- and post- reload user's <code>reset_digest</code> passes?<br>
  I thought it goes like this: <code>reset_digest</code> is <code>nil</code> at first, we post to <code>password_resets_path</code>, which is create action of <code>PasswordResetsController</code>; in this action we have <code>create_reset_digest</code> method. <code>reset_digest</code> isn't nil anymore, we reload it and our assert_not_equal passes.</p>
  
  <p>But if so, <code>@user</code> from fixtures should also have <code>reset_token</code> now (if its <code>reset_digest</code> was influenced by create action (specifically <code>create_reset_digest</code> method). </p>
  
  <p>Can someone please take a look? :)</p>
  
  <pre class="lang-rb prettyprint-override"><code>require 'test_helper'
  
  class PasswordResetsTest &lt; ActionDispatch::IntegrationTest
  
      def setup
          ActionMailer::Base.deliveries.clear
          @user = users(:michael)
          end
  
          test "password resets" do
              get new_password_reset_path
              assert_template 'password_resets/new'
              # Invalid email
              post password_resets_path, password_reset: { email: "" }
              assert_not flash.empty?
              assert_template 'password_resets/new'
              # Valid email
              post password_resets_path, password_reset: { email: @user.email }
              assert_not_equal @user.reset_digest, @user.reload.reset_digest
              assert_equal 1, ActionMailer::Base.deliveries.size
              assert_not flash.empty?
              assert_redirected_to root_url
              # Password reset form
              user = assigns(:user)
              # Valid password &amp; confirmation
              patch password_reset_path(user.reset_token),
              email: user.email,
              user: {
                  password: "foobaz",
                  password_confirmation: "foobaz"
              }
          end
      end
  
      def create_reset_digest
          self.reset_token = User.new_token
          #creating reset_digest
      end    
  
      def create
          @user = User.find_by(email: params[:password_reset][:email].downcase)
          if @user
              @user.create_reset_digest
  
          # ...
      end
  end
  </code></pre>