# Tests Losing Data (factory girl)

**URL:** <https://www.ruby-forum.com/t/tests-losing-data-factory-girl/191891>\
**Category:** Rails\
**Created:** [July 20, 2010, 12:38pm UTC](https://www.ruby-forum.com/t/tests-losing-data-factory-girl/191891 "2010-07-20T12:38:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ants\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/6de8d8/32.png) [@Ants\_P](https://www.ruby-forum.com/u/Ants_P)\
**Post date:** [July 20, 2010, 12:38pm UTC](https://www.ruby-forum.com/t/tests-losing-data-factory-girl/191891/1 "2010-07-20T12:38:11Z")

</div>

This is a cross post from the fg mailing list but the traffic is very  
low  
there so I thought I’d try here, too.

While running a test with Cukes/FG, I pre populate a table  
(event\_categories), run my test and it passes on a successful failure  
(duplicate record)

When the controller executes … render {:action =\> :new}, I get the  
following error …

You have a nil object when you didn’t expect it!  
You might have expected an instance of Array.  
The error occurred while evaluating nil.inject  
(ActionView::TemplateError)  
On line #10 of app/views/event\_types/\_form.html.erb

```
9: <%= form.label :event_category_id, 'Event Categories' %>
10: <%= form.select :event_category_id, @event_categories %>

```

Does anyone know what I have to do to preserve my data?

CIA

-ants

---

<div class="post-metadata">

**Author:** ![Ants\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/6de8d8/32.png) [@Ants\_P](https://www.ruby-forum.com/u/Ants_P)\
**Post date:** [July 20, 2010, 2:00pm UTC](https://www.ruby-forum.com/t/tests-losing-data-factory-girl/191891/2 "2010-07-20T14:00:45Z")

</div>

Solved. Sorry to take up bandwidth ☹

---

<div class="post-metadata">

**Author:** ![Ants\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/6de8d8/32.png) [@Ants\_P](https://www.ruby-forum.com/u/Ants_P)\
**Post date:** [July 20, 2010, 2:49pm UTC](https://www.ruby-forum.com/t/tests-losing-data-factory-girl/191891/3 "2010-07-20T14:49:02Z")

</div>

Ants P. wrote:

> Solved. Sorry to take up bandwidth ☹

Solved how? Please explain so others can learn.

---

<div class="post-metadata">

**Author:** ![Ants\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/6de8d8/32.png) [@Ants\_P](https://www.ruby-forum.com/u/Ants_P)\
**Post date:** [July 20, 2010, 3:15pm UTC](https://www.ruby-forum.com/t/tests-losing-data-factory-girl/191891/4 "2010-07-20T15:15:44Z")

</div>

On 20 July 2010 14:49, Marnen Laibow-Koser [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> To post to this group, send email to removed\_email\_address@domain.invalid.  
> To unsubscribe from this group, send email to  
> removed\_email\_address@domain.invalid[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> .  
> For more options, visit this group at  
> [http://groups.google.com/group/rubyonrails-talk?hl=en](http://groups.google.com/group/rubyonrails-talk?hl=en).
> 
> I didn’t want to advertise my stupidity 😉

in my create action, I was repopulating the event\_categories list after  
a  
successful save. In this instance, I was actually testing for a failure  
so  
the list never got touched.

Believe me, if I had a nugget of inspiration, I would’ve informed the  
list.  
Sorry for the vagueness in my solved reply.

-ants
