Internal changes for Rails v4.1.0 compatibility

Originally submitted here https://github.com/activerecord-hackery/ransack/pull/323. This along with the changes in polyamorous https://github.com/activerecord-hackery/polyamorous/pull/7 leaves the build with one failing spec which will be fixed if https://github.com/rails/rails/pull/13525 gets merged hopefully.