functional tests


Im stating to play with rails testing and have hit a slight snag that
i'm hoping someone can hit me with a clue bat for.

I have my models and associations set up correctly and all is working
as it should.

I only have the auto generated tests at the moment and the
test_should_get_index test is failing.

The controller is just a default controller but i get the following
error on the test as i modified the index view.

ActionView::TemplateError: You have a nil object when you didn't
expect it!
The error occurred while evaluating nil.real_name
    On line #13 of commits/index.html.erb

    11: <% for commit in @commits %>
    12: <tr>
    13: <td><%=h></td>
    14: <td><%=h %></td>
    15: <td><%=h commit.log %></td>
    16: <td><%=h %></td>

The commit controller as i say has not been modified since being

And the index method is

def index
    @commits = Commit.find(:all)

    respond_to do |format|
      format.html # index.html.erb
      format.xml { render :xml => @commits }

This works fine in normal usage so i guess i need to modify the test

The test looks like

require File.dirname(__FILE__) + '/../test_helper'

class CommitsControllerTest < ActionController::TestCase
  fixtures :commits, :people, :projects

  def test_should_get_index
    get :index
    assert_response :success
   assert_not_nil assigns(:commits)

Clearly i am missing something, i thought just loading the necessary
fixtures would make it work.

So what is the correct way to fix this?


Mark Kirby

My own stupid fault. I had not put the id's in my fixtures, no wonder it couldn't find anything.