Error: undefined method for nil:NilClass

When I test functionals, I get the following error:

<pre><code>test_should_display_index(AlertsControllerTest):
ActionView::TemplateError: undefined method `name' for nil:NilClass
    On line #9 of app/views/alerts/index.html.erb

        6:
        7: &lt;tr class=&quot;&lt;%= row_class %&gt;&quot;&gt;
        8: &lt;td scope=&quot;row&quot; class=&quot;first
odd&quot;&gt;&lt;%=h alert.title %&gt;&lt;/td&gt;
        9: &lt;td class=&quot;even&quot;&gt;&lt;%=h
alert.file_status.name %&gt;&lt;/td&gt;
        10: &lt;td class=&quot;last odd&quot;&gt;&lt;%= render
:partial =&gt; &quot;shared/action_links&quot;, :locals =&gt; { :obj
=&gt; alert, :type =&gt; &quot;alert&quot; } %&gt;
        11: &lt;/td&gt;
        12: &lt;/tr&gt;
</code></pre>

This test should confirm the proper display of the index for class
Alerts. Alerts belong to class FileStatuses. Each file_status contains
two objects: :id and :name.

<code>&lt;%=h alert.file_status.name %&gt;</code> produces the expected
result when viewed in a browser (either `draft`, `published` or `trash`
depending on the individual alert&#039;s setting). So it seems that the
only thing finding this error is the test.

The test is pretty straight forward.&nbsp; Its code is:

<pre><code>class AlertsControllerTest &lt; ActionController::TestCase

  test &quot;should display index&quot; do
    get :index
    assert_response :success
    assert_template &#039;index&#039;
    assert_not_nil assigns(@alert)
  end
end</code></pre>

So what am I doing wrong?

and of course, the source code is not escaped...

OK, I figured it out. I just needed to populate my fixtures (in
/tests/fixtures/). There is a good videocast addressing how to represent
these relationships here:
http://railscasts.com/episodes/81-fixtures-in-rails-2-0