Add Rails 4 support

This PR makes tests green with rails 4.0 and edge surveyor.
Manually checked that they still pass on rails 3.2 but haven't built any automatic switch yet.