views:

29

answers:

1

When saving an object by calling Entity.create(:name => "Entity1") from the Rails console in the testing environment (RAILS_ENV=test rails console) the "Entity1" object correctly appears in the test database (MySQL) when checking it with a mysql client. But when doing the same stuff in an rspec file (entity.create(:name => "Entity1"); sleep 100) and checking the test database during the sleep function, it appears to be completely empty. Why that? Where is the saved record? (I need it at that time in the database, cause of some Sphinx testing.)

I just like to add that querying the created Entity in the spec works fine (even if it doesn't appear in the database client). So it seems that Rails does here some miracle things that I don't really understand.

Even more strange (at least for me ;-)) ... when doing a Entity.connection.commit_db_transaction() after the object was created then the record suddenly appears in the database (but is not automatically cleaned up anymore).

A: 

The solution to that problem is a feature of Rails (or RSpec ... not sure about that) named Transactional Fixtures. When turning that off in the spec_helper.rb config.use_transactional_fixtures = false all records suddenly appear in the database after the objects are created (but that may lead to a lower test performance).

Zardoz