I fought left and right with rails 3 and a picker. There are a few stones that do not work properly if the rails application is not already loaded. factory_girl and shoulda are both examples, even on the rails3 branch. Taking as an example, when I try to run rake test:units , I get the following error:
DEPRECATION WARNING: RAILS_ROOT is deprecated! Use Rails.root instead. (called from autoload_macros at c:/code/test_harness/vendor/windows_gems/gems/shoulda-2.10.3/lib/shoulda/autoload_macros.rb:40) c:/code/test_harness/vendor/windows_gems/gems/shoulda-2.10.3/lib/shoulda/autoload_macros.rb:44:in 'join': can't convert #<Class:0x232b7c0> into String (TypeError) from c:/code/test_harness/vendor/windows_gems/gems/shoulda-2.10.3/lib/shoulda/autoload_macros.rb:44:in 'block in autoload_macros' from c:/code/test_harness/vendor/windows_gems/gems/shoulda-2.10.3/lib/shoulda/autoload_macros.rb:44:in 'map' from c:/code/test_harness/vendor/windows_gems/gems/shoulda-2.10.3/lib/shoulda/autoload_macros.rb:44:in 'autoload_macros' from c:/code/test_harness/vendor/windows_gems/gems/shoulda-2.10.3/lib/shoulda/rails.rb:17:in '<top (required)>'
Digging a little deeper into lib / shoulda / rails, I see this:
root = if defined?(Rails.root) && Rails.root
Rails.root
else
RAILS_ROOT
end
# load in the 3rd party macros from vendorized plugins and gems
Shoulda.autoload_macros root, File.join("vendor", "{plugins,gems}", "*")
So ... what happens when Rails.root is defined, Rails.root == nil, so RAILS_ROOT and RAILS_ROOT == nil are used, which is then passed to Shoulda.autoload_macros. Obviously, the rails application is not yet initialized. Now with Rails3 using the Bundler, there was some hubub on the Bundler side that could indicate the order in which the gems are needed, but I'm not sure if this will solve the problem. Ultimately, my questions are: when exactly does the environment.rb file (which actually initializes the application) get pulled in? Is there any harm when you run the application and execute it up to the Bundler.require line in config / application.rb? I tried to break the bundle to indicate the order myself, and first drew a rail vent, but it doesn't seem to me that requiring the gem rails to actually initialize the application.
Since this line (in config / application.rb) is called before the application is initialized, any gem in the vendor's gemfile that requires rail initialization is collected in the tank.
# Auto-require default libraries and those for the current Rails environment. Bundler.require :default, Rails.env
source share