title: receive_message_chain and smelly code
body: <p>I am testing my controller and there is a string that produces AR query:
  <code>current_user.providers.find(params[:id])</code>. I need it to return exactly the object I test, otherwise, the controller gets a reference that differs from the one I have in spec and some stubs like <code>allow(provider).to receive(:recreate)</code> do not work.</p>
  
  <p>The only way I found to do this is using <code>receive_message_chain</code> like this:
  <code>allow(provider.user).to receive_message_chain(:providers, :find =&gt; provider)</code>. But rspec documentation <a href="https://relishapp.com/rspec/rspec-mocks/v/3-6/docs/working-with-legacy-code/message-chains" rel="nofollow noreferrer">says</a> to consider using <code>receive_message_chain</code> as code that smells.
  In addition, I think later I may need to call <code>current_user.providers.find(otherid)</code> with another id, to get another object, so that would not work for me anymore.</p>
  
  <p>Is there any way to do it better? I have already managed to avoid <code>allow_any_instance_of</code>, that is also considered as smelly, so I believe there is a way to avoid this too, I just can't see it.
  If there's no, I at least wonder if there any way to add something like <code>with</code> to <code>receive_message_chain</code>?</p>
  
  <p>===========</p>
  
  <p>I just trying to test an <code>update</code> method of my controller.</p>
  
  <pre><code># app/controllers/restream/facebooks_controller.rb
  class Restream::FacebooksController &lt; Restream::BaseController
    def update
      current_user.providers.find(params[:id])
  
      if @fb.update_attributes(facebook_params)
        if event_changed?
          @fb.recreate
        else
          @fb.update
        end
        redirect_to restreams_path
      else
        render 'edit'
      end
    end
  end
  
  #spec/controllers/restream/facebooks_controller_spec.rb
  
  require 'rails_helper'
  
  describe Restream::FacebooksController do
    let!(:facebook) { create(:restream_facebook) }
    let!(:restream) { facebook.restream }
  
    before do
      login(restream.user)
    end
  
    describe '#update' do
      let!(:params_hash)  { {
          :title          =&gt; facebook.title,
          :privacy        =&gt; facebook.privacy,
          :destination    =&gt; facebook.destination,
          :destination_id =&gt; facebook.destination_id,
          :description    =&gt; facebook.description
        } }
      let!(:request_hash) { {
            :restream_facebook  =&gt; params_hash,
            :id                 =&gt; facebook.id
        } }
  
      before do
        allow(facebook.user).
          to receive_message_chain(:providers, :find =&gt; facebook)
        allow(facebook).to receive(:update)
        allow(facebook).to receive(:recreate)
      end
  
      context 'updates' do
        it 'title' do
          params_hash[:title] = SecureRandom.hex(2)
          post :update, request_hash
  
          expect(facebook.reload.title).to eq params_hash[:title]
        end
      end
    end
  end
  </code></pre>