title: controller rspec doesn't reload current_user or @user from database
body: <h2>FEATURE</h2>
  
  <p>A user has a profile and should be able to update it.</p>
  
  <hr>
  
  <h2>PROBLEM</h2>
  
  <p>I update the profile, for example change the name to "Homer Simpson", but all the assertions fail as the database record does not seem to update.</p>
  
  <p>I can't seem to get updated attributes:</p>
  
  <pre><code> Failure/Error: expect(subject.current_user.first_name).to eq('Homer')
  
     expected: "Homer"
          got: "Lew"
  
     (compared using ==)
   # ./spec/controllers/registrations_controller_spec.rb:67:in `block (3 levels) in &lt;top (required)&gt;'
  </code></pre>
  
  <p><strong>N.B.</strong> I have tried both <code>@user.reload</code> and <code>subject.current_user.reload</code></p>
  
  <p>Specs still not passing.</p>
  
  <hr>
  
  <h2>CODE</h2>
  
  <p>I am using:</p>
  
  <ul>
  <li>rails (4.0.0)</li>
  <li>devise (3.0.3)</li>
  <li>rspec-rails (2.14.0)</li>
  <li>capybara (2.1.0)</li>
  <li>factory_girl (4.2.0)</li>
  <li>database_cleaner (1.1.1)</li>
  </ul>
  
  <p>I have already checked:</p>
  
  <ul>
  <li>I've set the <code>devise.mapping</code> to user</li>
  <li>I don't have a <code>valid_session</code> polluting the devise session as <a href="https://stackoverflow.com/questions/9508707/rail3-rspec-devise-rspec-controller-test-fails-unless-i-add-a-dummy-subject-cur">per this other Stackoverflow thread</a>.</li>
  </ul>
  
  <p><strong>registrations_controller_spec.rb</strong></p>
  
  <pre><code>describe "User Profiles" do
    login_user
  
    it "Update - changes the user's attributes" do
      put :update, id: @user, user: attributes_for(:user, first_name: 'Homer')
      @user.reload
      expect(@user.first_name).to eq('Homer') # FAILS
    end
  end
  </code></pre>
  
  <p>I have tried swapping <code>@user</code> for <code>subject.current_user</code> like in this Stackoverflow thread: <a href="https://stackoverflow.com/questions/13037685/devise-rspec-registration-controller-test-failing-on-update-as-if-it-was-trying">"Devise Rspec registration controller test failing on update as if it was trying to confirm email address"</a></p>
  
  <pre><code>  put :update, id: subject.current_user, user: attributes_for(:user, first_name: 'Homer')
    subject.current_user.reload
    expect(subject.current_user.first_name).to eq('Homer') # Still FAILS
  </code></pre>
  
  <p>But it still fails.</p>
  
  <p>Is the problem in the controller? I find the user by <code>current_user.id</code> instead of via <code>params[:id]</code>.</p>
  
  <p><strong>registrations_controller.rb</strong></p>
  
  <pre><code>def update
    @user = User.find(current_user.id)
    email_changed = @user.email != params[:user][:email]
    password_changed = !params[:user][:password].blank?
  
    if email_changed or password_changed
      successfully_updated = @user.update_with_password(user_params)
    else
      successfully_updated = @user.update_without_password(user_params)
    end
  
    if successfully_updated
      sign_in @user, bypass: true # Sign in the user bypassing validation in case his password changed
      redirect_to user_profile_path, notice: 'Profile was successfully updated.'
    else
      render "edit"
    end
  end
  </code></pre>
  
  <p><strong>controller_macros.rb</strong> - defines <code>login_user</code> helper</p>
  
  <pre><code>module ControllerMacros
    def login_user    
      before(:each) do
        @request.env["devise.mapping"] = Devise.mappings[:user]
        @user = FactoryGirl.create(:user)
        @user.confirm!
        sign_in @user
      end
    end
  end
  </code></pre>
  
  <p>My integration specs pass fine. What am I missing here in the controllers?</p>