# Testing create action with associations

**URL:** <https://www.ruby-forum.com/t/testing-create-action-with-associations/112857>\
**Category:** Rails\
**Created:** [August 23, 2007, 10:32pm UTC](https://www.ruby-forum.com/t/testing-create-action-with-associations/112857 "2007-08-23T22:32:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robin\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c2a13f/32.png) [@Robin\_F](https://www.ruby-forum.com/u/Robin_F)\
**Post date:** [August 23, 2007, 10:32pm UTC](https://www.ruby-forum.com/t/testing-create-action-with-associations/112857/1 "2007-08-23T22:32:59Z")

</div>

Hi,

In my objects controller, I call the following in order to create an  
object:

def create  
@object = @account.objects.build params[:object]

```
respond_to do |format|
  if @object.save

```

…  
end

The account variable is populated by a before filter in  
application.rb.

When I try to test this though, I keep receiving a nil object error.  
It seems to be that the test does not recognise the before filter and  
therefore cannot create the object.

How do I make my test recognise the account variable?

Thanks in advance.

Robin

---

<div class="post-metadata">

**Author:** ![Robin\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c2a13f/32.png) [@Robin\_F](https://www.ruby-forum.com/u/Robin_F)\
**Post date:** [August 25, 2007, 9:51pm UTC](https://www.ruby-forum.com/t/testing-create-action-with-associations/112857/2 "2007-08-25T21:51:14Z")

</div>

Robin F. wrote:

> …
> 
> Thanks in advance.
> 
> Robin
> 
> >

If it’s a functional test, the filter will be run (assuming it’s being  
called), so there’s probably some other problem. You can try putting a  
logger.debug “this has been run and @account = #{@account.inspect}” in  
the filter, and then checking the logs, or a: p assigns(:account).  
Hope this helps  
Chris

## –

Autopendium :: Stuff about old cars  
[http://autopendium.com](http://autopendium.com)
