This has been recently fixed in master and back-ported to 3.2 branch:
See https://github.com/rails/rails/issues/736 for the original bug report, https://gist.github.com/1754727 for monkey patches and github.com/rails/rails/pull/4918 for accepted pull request.