Posted on April 24, 2006
This caught me out. My rails unit tests seemed to work on one of my Macs and not on the other. It looked like rails wasn't reloading my fixtures (or rolling back) between test methods so one test was messing up future tests. It turned out it that the tables I was creating in my development database (with CocoaMySQL) were using the MyISAM storage mechanism (which is the MySQL default) and that format was being carried over to my test database because I had set config.active_record.schema_format = :sql in my environment.rb (for other reasons). A helpful comment in test_helper.rb set me straight:
# Every Active Record database supports transactions except MyISAM tables
# in MySQL. Turn off transactional fixtures in this case; however, if you
# don't care one way or the other, switching from MyISAM to InnoDB tables
# is recommended.
self.use_transactional_fixtures = true
Now I just have to figure out how to switch MySQLs default table type to InnoDB.
Filed under: Projects |
Tagged with: mysql testing |
0 comments
Posted on April 23, 2006
After a slightly rocky start with rails 1.1, I think I have things under control. Everything seemed to break at first, (webrick would refuse to start along with scripts/console) but I soon discovered that most of my problems were due to a rogue second ruby installation (left over from my experiments with YARV I think).
There are a couple of ongoing problems though. The main one is that my ActiveRecord objects stored directly on the session (e.g. @session[:user]) are having their references and collections marshalled to disk. So I end up with larger and larger serialised session files in tmp/ and stale data accumulating from request to request. Not good!
I thought I was going crazy because no-one else seems to be experiencing the same problems as me. I found some code in the active_record gem to do with invalidating the references and collections on session objects but nothing seems to have changed. Also, someone else has reported the same problem so it seems I'm not alone. I tried switching to ActiveRecordStore for saving sessions but it didn't help. The strange things is that the references are being cleared (I checked with some logging in the core active record sources), I just still end up with stale data at the beginning of each request. It must be being cached somewhere else.
andylien's workaround of adding an after_filter to the application controller that calls @session[:user].clear_association_cache seems to fix things, at least for now.
Filed under: Projects |
Tagged with: activerecord |
1 comment