Db test does not roll back after each run

UPDATE: FIXED !!!!! Since I suspected that it was a configuration that was somehow corrupted, it caused a lot of hairs. For some reason, "require" test_help "" was removed from test_helper.rb, it is added again, and all tests are now complete.

It smells like a basic configuration problem, but I can't figure that out. Rails 2.3.5, patch Ruby 1.8.7 173. I use Girl-Girl + factory, and I have a test that creates a couple of users to customize

class UserTest < ActiveSupport::TestCase use_transactional_fixtures = true context "getting a user email" do setup do ... stubs ... end should "populate email field if not present" do @user = Factory.create(:molly_perkins) @user.get_email(@facebook_session) assert_equal ' molly.perkins.test@gmail.com ', @user.email end should "not populate email if already present" do @user = Factory.create(:amanda_levy) @user.get_email(@facebook_session) assert_equal ' amandalevy06@gmail.com ', @user.email end end end 

The test passes, but the problem is that they are not cleared after starting - looking at test.log, I see that the transactions fix the inserts! What gives?

  # First test User Create (0.3ms) INSERT INTO `users` ... SQL (0.4ms) COMMIT # Second test SQL (0.1ms) BEGIN User Create (0.3ms) INSERT INTO `users` .... SQL (0.4ms) COMMIT SQL (0.1ms) BEGIN User Update (0.4ms) UPDATE `users` .... SQL (0.4ms) COMMIT 

To get around this, I just use the tracking block "Model.all.each (&: destroy)", but I do not need to do this, and it must / janky slowly destroy everything. I create an instance. Transactions should just be rolled back ...

Table in test database - InnoDB:

 mysql> select engine from tables where table_name = 'users' and table_schema = 'voltron_test'; +--------+ | engine | +--------+ | InnoDB | +--------+ 

and I use transactional devices (from test_helper.rb):

 class ActiveSupport::TestCase use_transactional_fixtures = true end 

Transactions really work (access to the test database from the console):

 mysql> select * from users; Empty set (0.00 sec) mysql> BEGIN; Query OK, 0 rows affected (0.00 sec) mysql> INSERT INTO `users` ... Query OK, 1 row affected (0.00 sec) mysql> select * from users; ... 1 row in set (0.00 sec) mysql> ROLLBACK; Query OK, 0 rows affected (0.00 sec) mysql> select * from users; Empty set (0.00 sec) 
+4
source share
3 answers

I never used use_transaction_fixtures = true in a test case, but had alwsays:

 class Test::Unit::TestCase .... self.use_transactional_fixtures = true .... end 

in the test / test_helper.rb file that comes with Rails and never had this problem.

+3
source

If you use the myISAM db engine, this is pretty normal since it does not support transactions.

0
source

Small point, but you must have self.use_transactional_fixtures = true

"I" is necessary.

0
source

All Articles