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

See https://github.com/rails/rails/issues/17119 for the back story.
I think that this is safe ; the test's name is pretty clear and there's always `git blame`. :-)