# Unit test failing

**URL:** <https://www.ruby-forum.com/t/unit-test-failing/113573>\
**Category:** Rails\
**Created:** [September 2, 2007, 2:52am UTC](https://www.ruby-forum.com/t/unit-test-failing/113573 "2007-09-02T02:52:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dnstevenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8dc957/32.png) [@dnstevenson](https://www.ruby-forum.com/u/dnstevenson)\
**Post date:** [September 2, 2007, 2:52am UTC](https://www.ruby-forum.com/t/unit-test-failing/113573/1 "2007-09-02T02:52:08Z")

</div>

I have unit tests set up with “self.use\_transactional\_fixtures =  
true”, so each test should roll back.

Run individually, all my tests succeed. But running “rake  
test:units”, I get the below error in 5 test cases. I’m not sure how  
to solve this since I’m not sure how to debug tasks run thru rake. Any  
ideas are appreciated.

1. Error:  
test\_delete(OrderTest):  
ActiveRecord::RecordInvalid: Validation failed: Orders is invalid  
/var/lib/gems/1.8/gems/activerecord-1.15.3/lib/active\_record/  
validations.rb:764:in `save_without _transactions!' /var/lib/gems/1.8/gems/activerecord-1.15.3/lib/active_record/ transactions.rb:133:in`save!’  
/var/lib/gems/1.8/gems/activerecord-1.15.3/lib/active\_record/  
connection\_adapters/abstract/databa  
se\_statements.rb:59:in `transaction' /var/lib/gems/1.8/gems/activerecord-1.15.3/lib/active_record/ transactions.rb:95:in`transaction’  
/var/lib/gems/1.8/gems/activerecord-1.15.3/lib/active\_record/  
transactions.rb:121:in `transaction ' /var/lib/gems/1.8/gems/activerecord-1.15.3/lib/active_record/ transactions.rb:133:in`save!’  
./test/unit/order\_test.rb:13:in `test\_delete’

---

<div class="post-metadata">

**Author:** ![dnstevenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8dc957/32.png) [@dnstevenson](https://www.ruby-forum.com/u/dnstevenson)\
**Post date:** [September 2, 2007, 3:29am UTC](https://www.ruby-forum.com/t/unit-test-failing/113573/2 "2007-09-02T03:29:11Z")

</div>

On Sep 1, 2007, at 8:51 PM, dailer wrote:

> ActiveRecord::RecordInvalid: Validation failed: Orders is invalid  
> /var/lib/gems/1.8/gems/activerecord-1.15.3/lib/active\_record/  
> transactions.rb:121:in `transaction ' /var/lib/gems/1.8/gems/activerecord-1.15.3/lib/active_record/ transactions.rb:133:in `save!’  
> ./test/unit/order\_test.rb:13:in `test\_delete’

Area all of your database tables capable of supporting transactions?  
For example, if you are using MySQL, the MyISAM engine does not  
support transactions, but the InnoDB engine does.

You can check with:

mysql\> show create table users\G  
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* 1. row \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
Table: users  
Create Table: CREATE TABLE `users` (  
`id` int(11) NOT NULL auto\_increment,  
`username` varchar(255) default NULL,  
`hashed_password` varchar(255) default NULL,  
`email` varchar(255) default NULL,  
`created_at` datetime default NULL,  
`updated_at` datetime default NULL,  
…  
PRIMARY KEY (`id`),  
UNIQUE KEY `users_username_index` (`username`)  
) ENGINE=InnoDB DEFAULT CHARSET=utf8  
1 row in set (0.00 sec)

Notice the “ENGINE=InnoDB” at the end.

If you are NOT using MySQL, then you probably need to supply more  
information about your environment.

(For me, usually it’s the opposite problem, all tests run fine, but  
individually one doesn’t work and that tends to point to missing  
fixture declarations in the test that fails.)

-Rob

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![dnstevenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8dc957/32.png) [@dnstevenson](https://www.ruby-forum.com/u/dnstevenson)\
**Post date:** [September 2, 2007, 5:00am UTC](https://www.ruby-forum.com/t/unit-test-failing/113573/3 "2007-09-02T05:00:16Z")

</div>

thx, but I’m using postgres.

---

<div class="post-metadata">

**Author:** ![dnstevenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8dc957/32.png) [@dnstevenson](https://www.ruby-forum.com/u/dnstevenson)\
**Post date:** [September 2, 2007, 3:58pm UTC](https://www.ruby-forum.com/t/unit-test-failing/113573/4 "2007-09-02T15:58:09Z")

</div>

like I said in my original post, they ALL run successfully when run  
individually. That’s what makes no sense about this, especially since  
I’m rolling back after each test. Also, I’m not using fixtures because  
I have fk constraints and found it hard to use fixtures.

appreciate the input tho…

---

<div class="post-metadata">

**Author:** ![dnstevenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8dc957/32.png) [@dnstevenson](https://www.ruby-forum.com/u/dnstevenson)\
**Post date:** [September 2, 2007, 6:26am UTC](https://www.ruby-forum.com/t/unit-test-failing/113573/5 "2007-09-02T06:26:20Z")

</div>

On Sep 1, 9:58 pm, dailer [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> thx, but I’m using postgres.

Check all of your fixtures lines. 99% of the time when this happens  
to me, that’s the cause. I’ve added some functionality that now uses  
a model that it never used before, and so I need to update the fixture  
statement - even if the tests in question don’t appear that they need  
those other fixtures.

Barring that, you can try to run one file at a time:

ruby test/unit/something\_test.rb

and see if at least the whole file can be run at once. That might  
also help narrow down the problem.

Jeff

> **[Hey Daddio!](http://softiesonrails.com)**
>
> Home of Hey Daddio Software

[essentialrails.com](http://essentialrails.com)
