sandro / specjour

distributed rspec & cucumber via bonjour
MIT License
212 stars 33 forks source link

Fix preinitialization errors in gems like has_many_polymorphs #18

Closed ahawkins closed 11 years ago

ahawkins commented 13 years ago

I've got a project that uses has many polymorphs. When Rails is loaded it connects to the DB to look at columns to preload all the stuff it needs to create its relation. This caused a problem with specjour since load_app (in Worker) is called before Configuration.after_fork. So when load_app was called, ENV['TEST_ENV_NUMBER'] is present which changes the database. However, since the default after_fork(DBScrub) is called after the app was loaded this created a state where the forked Rails app is trying to access a DB that isn't created yet. I think this may also solve a problem with ActiveScaffold which does roughly the same thing. When a ActiveScaffold controller is loaded it connects to the db to read column information (which will cause a problem if the DB is not created).

tl;dr: moved Configuration.after_fork.call to before load_app to fix issues with libraries that connect to the DB when files are loaded