Upgrade to Rails 4.0.2, fix tests and remove deprecation warnings