Hi,
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.
test_should_get_index(CommitsControllerTest): 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
10: 11: <% for commit in @commits %> 12: <tr> 13: <td><%=h commit.person.real_name.name%></td> 14: <td><%=h commit.project.name %></td> 15: <td><%=h commit.log %></td> 16: <td><%=h commit.date %></td>
The commit controller as i say has not been modified since being generated
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 } end end
This works fine in normal usage so i guess i need to modify the test somehow.
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) end
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?
Thanks
Mark Kirby