Unit test failing

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:
    ActiveRecord::RecordInvalid: Validation failed: Orders is invalid
    validations.rb:764:in save_without _transactions!' /var/lib/gems/1.8/gems/activerecord-1.15.3/lib/active_record/ transactions.rb:133:insave!’
    se_statements.rb:59:in transaction' /var/lib/gems/1.8/gems/activerecord-1.15.3/lib/active_record/ transactions.rb:95:intransaction’
    transactions.rb:121:in transaction ' /var/lib/gems/1.8/gems/activerecord-1.15.3/lib/active_record/ transactions.rb:133:insave!’
    ./test/unit/order_test.rb:13:in `test_delete’

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

ActiveRecord::RecordInvalid: Validation failed: Orders is invalid
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,

UNIQUE KEY users_username_index (username)
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 B. http://agileconsultingllc.com
[email protected]

thx, but I’m using postgres.

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…

On Sep 1, 9:58 pm, dailer [email protected] 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.