title: Rails Unit Testing - Cannot redirect to nil!
body: <p>A contact has_many notes; notes belong_to a contact.  In my notes controller, after a successful save of a Note, I redirect to the note's contact using:</p>
  
  <pre><code>format.html { redirect_to(@note.contact, :notice =&gt; 'Note was successfully created.') }
  </code></pre>
  
  <p>In my unit test, I'm testing the ability to create a note and redirect to the note's contact view page.  My notes.yml fixture simply sets up the note, and in the setup portion of the notes_controller_test.rb I assign the note from the fixture to @note.</p>
  
  <p>Here's the actual test code:</p>
  
  <pre><code>test "should create note" do
    assert_difference('Note.count') do
      post :create, :note =&gt; @note.attributes
    end
  end
  </code></pre>
  
  <p>I think the note is successfully saving, but the redirect is failing. So it looks like the redirect_to in the controller is throwing up the "Cannot redirect to nil!" error, but I can't seem to understand why.</p>
  
  <p>Here is my Notes create action:</p>
  
  <pre><code>def create
  @note = Note.new(params[:note])
  
  respond_to do |format|
    if @note.save
      format.html { redirect_to(@note.contact, :notice =&gt; 'Note was successfully created.') }
      format.xml  { render :xml =&gt; @note.contact, :status =&gt; :created, :location =&gt; @note.contact }
    else
      format.html { render :action =&gt; "new" }
      format.xml  { render :xml =&gt; @note.contact.errors, :status =&gt; :unprocessable_entity }
    end
  end
  </code></pre>
  
  <p>end</p>