Use define_method when method name contains weird characters.

In delegate_to_scoped_klass method in ActiveRecord, plain def was used when defining methods with weird characters in names, which resulted in syntax errors. I've changed it to use define_method instead and added a regression test for scope names with spaces.

This could be also rewritten to use a block instead of a string in module_eval, but in pull request #9206 I've read that it may impose some performance penalty, so I didn't change it as I don't know how important it is.