Ensure HABTM relationships produce valid class names (Fixes #17119)

See https://github.com/rails/rails/issues/17119 for the back story.
@tenderlove Because `HABTM_*` classes are built under the ActiveRecord model's namespace, there are multiple levels we need to check for constants.

In Ruby 1.9.3, [`const_get`](http://ruby-doc.org/core-1.9.3/Module.html#method-i-const_get) does not look recursively if we pass in `Developer::HABTM_Projects` for instance, while 2.0 mentions "[this method will recursively look up constant names if a namespaced class name is provided](http://ruby-doc.org/core-2.0/Module.html#method-i-const_get).

Although I couldn't find it documented, I noticed the same behavior when using `const_defined?` (which was the reason the original pull request failed on 2.0 and 1.9.3).

We could create our own recursive lookup, but that seems worse to me.

I suppose we could just try accessing the constant under `assert_nothing_raised` ... I'll try that.