Answer: it varies by environment (webrick/mongrel, mysql native/simple), and, of course, you should require it for yourself.
As rails boots, ‘digest/sha1′ may or may not be required automatically, depending on your environment and gems. So if you’ve referred to Digest::SHA1 without requiring that file yourself (tsk!), you may get:
The error "NameError: uninitialized constant Digest::SHA1"
- It is required automatically by the pure ruby mysql library, but not by the native mysql gem (2.7)
- It is required automatically by webrick (1.3.1), but not by mongrel (1.0.1)
Obviously, you should require what you need explicitly, where you need it, rather than depending upon it being loaded for you in the environment. That’s simple to fix, but I spent a bit of time trying to find out why the problem existed on only some machines and not others, running identical code. (Not my codebase). Some of these environments fail to find Digest::SHA1 and some of them had no problems because they were running with mongrel instead of webrick, or had the native mysql gem installed.
This is another reason to nail down your development platform with your colleagues; mongrel’s a drop in replacement for webrick in some respects, but its interface with your code is a complex one.
It ought to go without saying that your testing environment should resemble your production environment as closely as possible.
Ways to test:
You can detect if mysql’s class loading has had an effect by doing
ruby script/runner 'Digest::SHA1'
or
ruby script/console
Digest::SHA1
Both will pass if you don’t have the native mysql gem installed, and may fail if you do (depends on the rest of your env).
To test whether or not web server’s loading the class, I guess you could put the same line at the end of environment.rb, or just hit a page that tries to use Digest::SHA1.
Another way to find out if the class is being required, in any environment, which also allows you to see WHERE it is being required, is to hack the require mechanism to be a tell-tale.
I’m on rails 1.2.1, mongrel 1.0.1, webrick 1.3.1, mysql gem 2.7, ruby 1.8.5 on mac os x 10.4