# Functional tests

**URL:** <https://www.ruby-forum.com/t/functional-tests/124704>\
**Category:** Rails\
**Created:** [January 1, 2008, 12:00pm UTC](https://www.ruby-forum.com/t/functional-tests/124704 "2008-01-01T12:00:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![site-master](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/13edae/32.png) [@site-master](https://www.ruby-forum.com/u/site-master)\
**Post date:** [January 1, 2008, 12:00pm UTC](https://www.ruby-forum.com/t/functional-tests/124704/1 "2008-01-01T12:00:26Z")

</div>

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 K.

---

<div class="post-metadata">

**Author:** ![site-master](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/13edae/32.png) [@site-master](https://www.ruby-forum.com/u/site-master)\
**Post date:** [January 1, 2008, 1:47pm UTC](https://www.ruby-forum.com/t/functional-tests/124704/2 "2008-01-01T13:47:31Z")

</div>

On 1 Jan 2008, at 10:59, Mark K. wrote:

> 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.

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

mark
