schtieF wrote:
i have a very strange and serious problem. In my test i create an
object with (ActiveRecord::Base).create (i also tried .new and .save!)
everything seems to be fine, assert *.errors.empty? is ok
but there is ne entry in the database.
I used the debugger command and put it right after create/save and
printed out the local variables.
The strange thing is, that i see a database id in the object, so it
must be in the db cause its an autoincrement field.
I also double-checked my database.yml settings for test, tried to
refer to a non existing db and got the right error.
Add to your test, after the create line, this...
sleep 80
...and turn off the line in test_helper.rb that says something about transactional fixtures.
Then run the test, go to another shell, and look in the database for your record.
The deal is that to preserve test isolation, the fixture system erases the entire database between each test case. That's why I offered the sleep trick - to see the record before the next test zilches it.
Then, because erasing and rebuilding the entire database is inefficient, the test runner also has the option to build the database once (AFAIK), and then run each test case in a transaction. When the transaction rolls back, the data fixtures reappear in the correct state for the text test.
Because one user (actually one database connection) cannot see the changes in another connection's transaction until it commits, and because our transactions will never commit, you must disable the transaction system to see your new record.
Going forward, put your sample records into test/fixtures/*yml, and then use rake db:fixtures:load to populate your development database for manual testing.