Add Rails 4.0 / 4.1 support

I did some pre-upgrade updates and cleanup, then added support for Rails 4.0 and 4.1 while keeping backwards-compatibility for 3.2.x.

The most significant changes were in `has_many_as_polymorph` to handle the new `has_many` arguments.