Rails 4 support

HI,

This pull-request adds Rails 4 support.

Please see commit messages for detailed changes.

Test suite

* edge rails = pass
* 3-2-stable = pass
* 3-1-stable = 1 fails (the same one fails in upstream/master)
* 3-0-stable = 4 fails (the same ones fail in upstream/master)

Please let me know if you have any questions. I will be glad to answer.