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

See https://github.com/rails/rails/issues/17119 for the back story.
we can't have failing jruby test in travis. We either have to turn on `ObjectSpace` or skip this test in jruby.

cc @senny @jeremy @tenderlove @rafaelfranca