Not sure this is known behaviour but it seems that if want to set the
environment to, for example, test, and you want to use Active Record you
have to both explicitly set the RAILS_ENV and the BackgrounDRb environment.
So, if you have a config file backgroundrb_test.yml (as well as the
default) and set the environment to test in that, this is what *seems*
to happen:
$ script/backgroundrb/start # starts backgroundrb in development
environment and uses AR in development environment
$ script/backgroundrb/start -c backgroundrb_test # starts
backgroundrb in test environment but uses AR in development
environment, leading to weird shit with fixtures and so on.
$ script/backgroundrb/start -c backgroundrb_test # starts
backgroundrb in test environment but uses AR in development
environment, leading to weird shit with fixtures and so on.
$ RAILS_ENV=test script/backgroundrb/start # starts backgroundrb in
development environment but I think uses AR in test environment --
not sure what end result is here.
$ RAILS_ENV=test script/backgroundrb/start -c backgroundrb_test #
starts backgroundrb in test environment and AR in test environment.
All tickety-boo and working as expected.
As I said, this may be expected behaviour, but it confused me for a
while and meant my tests (which use mocks) seemed to behaving very
oddly. Hope this helps someone else in the future.
Cheers
CT
Chris T wrote:> Not sure this is known behaviour but it seems that if want to set the > environment to, for example, test, and you want to use Active Record you > have to both explicitly set the RAILS_ENV and the BackgrounDRb environment.I ran into essentially the same problem (needing to run BRB in the test environment so AR would use the right DB). My "solution" was to add entries in backgroundrb.yml for environment, log_file and pid_file to allow for multiple instances of BRB to run simultaneously in different environments. My config now looks like: environment: <%= ENV[''RAILS_ENV''] %> port: <%= 22222 + [''production'', ''development'', ''test''].index(ENV[''RAILS_ENV'']) %> log_file: <%= "log/brb-#{ENV[''RAILS_ENV'']}.log" %> pid_file: <%= "log/brb-#{ENV[''RAILS_ENV'']}.pid" %> ... Obviously, I had to hack BRB to use these settings, modify the start/stop scripts to take an --env argument, and add Rake tasks to (re)start the test instance. Add that restart task as a preqreq of ''test'', and the BRB test instance will restart (and reload) before each test run. If interested, I can provide diffs ... -- Steve