# Unit tests leave data behind when they should not

**URL:** <https://www.ruby-forum.com/t/unit-tests-leave-data-behind-when-they-should-not/55336>\
**Category:** Rails\
**Created:** [March 20, 2006, 2:40am UTC](https://www.ruby-forum.com/t/unit-tests-leave-data-behind-when-they-should-not/55336 "2006-03-20T02:40:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sserdyuk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9a28c/32.png) [@sserdyuk](https://www.ruby-forum.com/u/sserdyuk)\
**Post date:** [March 20, 2006, 2:40am UTC](https://www.ruby-forum.com/t/unit-tests-leave-data-behind-when-they-should-not/55336/1 "2006-03-20T02:40:30Z")

</div>

Hi,

I was confused yesterday. I have bunch of tests and one of those was  
testing ActiveRecord::save and it was all right, but next method failed  
because table still had newly created record. All documentation suggests  
that it should not be the case and that data is reloaded from fixtures  
before every method is run.  
I am running edge rails and really did not have anything special done  
about unit testing setup.  
Anybody can suggest where to look for the cause?

Sergei

---

<div class="post-metadata">

**Author:** ![sserdyuk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9a28c/32.png) [@sserdyuk](https://www.ruby-forum.com/u/sserdyuk)\
**Post date:** [March 20, 2006, 3:05am UTC](https://www.ruby-forum.com/t/unit-tests-leave-data-behind-when-they-should-not/55336/2 "2006-03-20T03:05:12Z")

</div>

Since 1.0, Rails tries to use transactions during testing, to help  
with performance. So, if you’re database does not support  
transactions, the tests won’t work correctly. If you’re using MySQL,  
you can enable transactions by attaching “engine = innodb” to the end  
of your create table statements. Alternatively, you can add this  
line to your test classes:

self.use\_transactional\_fixtures = false

Hope that helps,

Tim

---

<div class="post-metadata">

**Author:** ![sserdyuk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9a28c/32.png) [@sserdyuk](https://www.ruby-forum.com/u/sserdyuk)\
**Post date:** [March 20, 2006, 5:27pm UTC](https://www.ruby-forum.com/t/unit-tests-leave-data-behind-when-they-should-not/55336/3 "2006-03-20T17:27:53Z")

</div>

Thank you Tim.

> Hope that helps,
> 
> Tim

---

<div class="post-metadata">

**Author:** ![sserdyuk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9a28c/32.png) [@sserdyuk](https://www.ruby-forum.com/u/sserdyuk)\
**Post date:** [March 20, 2006, 5:39pm UTC](https://www.ruby-forum.com/t/unit-tests-leave-data-behind-when-they-should-not/55336/4 "2006-03-20T17:39:57Z")

</div>

In mySQL you can alter an existing table (named table\_name) to use  
InnoDB with the command:

mysql\> alter table table\_name TYPE=InnoDB;

just substitute your table name, and run at the mysql prompt (or however  
you prefer to run stand alone sql.

-sean

Timothy B. wrote:

> Since 1.0, Rails tries to use transactions during testing, to help  
> with performance. So, if you’re database does not support  
> transactions, the tests won’t work correctly. If you’re using MySQL,  
> you can enable transactions by attaching “engine = innodb” to the end  
> of your create table statements. Alternatively, you can add this  
> line to your test classes:
> 
> self.use\_transactional\_fixtures = false
> 
> Hope that helps,
> 
> Tim
