# MySQL transactions not working in unit tests?

**URL:** <https://www.ruby-forum.com/t/mysql-transactions-not-working-in-unit-tests/123561>\
**Category:** Rails\
**Created:** [December 18, 2007, 8:06pm UTC](https://www.ruby-forum.com/t/mysql-transactions-not-working-in-unit-tests/123561 "2007-12-18T20:06:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ed\_ruder](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/d9b06d/32.png) [@ed\_ruder](https://www.ruby-forum.com/u/ed_ruder)\
**Post date:** [December 18, 2007, 8:06pm UTC](https://www.ruby-forum.com/t/mysql-transactions-not-working-in-unit-tests/123561/1 "2007-12-18T20:06:52Z")

</div>

I just installed acts\_as\_authenticated into an app and one of its unit  
tests is failing. The cause is that another unit test’s changes to the  
AAA fixtures aren’t being rolled back. I’m confused, since I have  
transactional fixtures turned on and MySQL InnoDB engine being used.

Details:

- MySQL 5.0.24. InnoDB is the default engine, all tables in the test  
db are using the InnoDB engine.
- Stock AAA unit tests.
- The unit test in question, test\_should\_reset\_password, succeeds when  
run by itself, fails when run with all of the unit tests. (I’m using  
autotest, so when I touch the unit test file, I see the test succeed  
in isolation, then the same test fails when run with all of the  
tests.)
- test.log clearly shows the unit tests being wrapped in BEGIN/  
ROLLBACK pairs
- If I modify the other unit test, test\_should\_not\_rehash\_password, to  
explicitly undo the db changes it does, all tests pass, in isolation  
and collectively.
- I have slightly modified AAA’s User model, but I can’t see how the  
modifications could come into play in this case. (This is integrating  
into a legacy database with some different conventions.)

Code at [Parked at Loopia](http://pastie.caboo.se/128208)

Any suggestions are much appreciated! (I don’t have enough hair to be  
pulling so much out!)

Ed

---

<div class="post-metadata">

**Author:** ![ed\_ruder](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/d9b06d/32.png) [@ed\_ruder](https://www.ruby-forum.com/u/ed_ruder)\
**Post date:** [December 19, 2007, 12:55am UTC](https://www.ruby-forum.com/t/mysql-transactions-not-working-in-unit-tests/123561/2 "2007-12-19T00:55:37Z")

</div>

BTW, turning off transactional fixtures in test\_helper.rb results in  
all AAA tests passing. Turn back on, they fail. For now, that’s my  
workaround. Slower tests, but they work as I expect them to.

Ed

---

<div class="post-metadata">

**Author:** ![ed\_ruder](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/d9b06d/32.png) [@ed\_ruder](https://www.ruby-forum.com/u/ed_ruder)\
**Post date:** [December 26, 2007, 11:20am UTC](https://www.ruby-forum.com/t/mysql-transactions-not-working-in-unit-tests/123561/3 "2007-12-26T11:20:54Z")

</div>

Check that your tables are InnoDB and not MyISAM.

---

<div class="post-metadata">

**Author:** ![ed\_ruder](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/d9b06d/32.png) [@ed\_ruder](https://www.ruby-forum.com/u/ed_ruder)\
**Post date:** [December 29, 2007, 7:27am UTC](https://www.ruby-forum.com/t/mysql-transactions-not-working-in-unit-tests/123561/4 "2007-12-29T07:27:28Z")

</div>

Yep. As I said in the initial post:
