# Model records are not saved to database in during tests

**URL:** <https://www.ruby-forum.com/t/model-records-are-not-saved-to-database-in-during-tests/63088>\
**Category:** Rails\
**Created:** [June 11, 2006, 10:38pm UTC](https://www.ruby-forum.com/t/model-records-are-not-saved-to-database-in-during-tests/63088 "2006-06-11T22:38:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roman\_LE\_NEGRATE](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9d8465/32.png) [@Roman\_LE\_NEGRATE](https://www.ruby-forum.com/u/Roman_LE_NEGRATE)\
**Post date:** [June 11, 2006, 10:38pm UTC](https://www.ruby-forum.com/t/model-records-are-not-saved-to-database-in-during-tests/63088/1 "2006-06-11T22:38:27Z")

</div>

Hi,

I’m trying to do unit tests which should save informations into a  
database that another computer should be able to get while the test  
is running.

The problem is although my unit test class has  
“use\_transactional\_fixtures” set to false, when I create a new  
instance of a model and save it, it does not actually appear in the  
database when connecting to this same database with the “mysql”  
command line tool. The fixtures are the only present records.

My question is: how to do so that the records actually get inserted  
into the test database ?

Thank you :-).

---

<div class="post-metadata">

**Author:** ![Roman\_LE\_NEGRATE](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9d8465/32.png) [@Roman\_LE\_NEGRATE](https://www.ruby-forum.com/u/Roman_LE_NEGRATE)\
**Post date:** [June 11, 2006, 10:44pm UTC](https://www.ruby-forum.com/t/model-records-are-not-saved-to-database-in-during-tests/63088/2 "2006-06-11T22:44:53Z")

</div>

(Sorry for the careless mistake in the title)

---

<div class="post-metadata">

**Author:** ![Roman\_LE\_NEGRATE](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9d8465/32.png) [@Roman\_LE\_NEGRATE](https://www.ruby-forum.com/u/Roman_LE_NEGRATE)\
**Post date:** [June 12, 2006, 6:45pm UTC](https://www.ruby-forum.com/t/model-records-are-not-saved-to-database-in-during-tests/63088/3 "2006-06-12T18:45:25Z")

</div>

> My question is: how to do so that the records actually get inserted  
> into the test database ?

Unfortunately, this Rails behaviour prevents me from going further in  
my project.  
Does anybody have an idea ?

---

<div class="post-metadata">

**Author:** ![Roman\_LE\_NEGRATE](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9d8465/32.png) [@Roman\_LE\_NEGRATE](https://www.ruby-forum.com/u/Roman_LE_NEGRATE)\
**Post date:** [June 12, 2006, 7:01pm UTC](https://www.ruby-forum.com/t/model-records-are-not-saved-to-database-in-during-tests/63088/4 "2006-06-12T19:01:42Z")

</div>

On Monday, June 12, 2006, at 6:42 PM, Roman LE NEGRATE wrote:

> > My question is: how to do so that the records actually get  
> > inserted \> into the test database ?
> 
> Unfortunately, this Rails behaviour prevents me from going further  
> in my project.  
> Does anybody have an idea ?
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

This is normal testing behavior. For each test the database is  
populated with your fixtures and then torn down again at the end. This  
prevents tests from being dependent on each other.

To get around this behavior you will need to do some hackery in the  
Testing code. You may want to define a new ‘environment’ called  
‘distributed-test’ and then patch the testing code to skip the database  
rollback in that case. Just remember that your tests may behave oddly  
since they are no longer independent of each other unless you manually  
reload the data.

\_Kevin

---

<div class="post-metadata">

**Author:** ![Roman\_LE\_NEGRATE](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9d8465/32.png) [@Roman\_LE\_NEGRATE](https://www.ruby-forum.com/u/Roman_LE_NEGRATE)\
**Post date:** [June 13, 2006, 9:52am UTC](https://www.ruby-forum.com/t/model-records-are-not-saved-to-database-in-during-tests/63088/5 "2006-06-13T09:52:21Z")

</div>

> since they are no longer independent of each other unless you manually  
> reload the data.

Thank you Kevin.
