fix regression for rails issue #9994

https://github.com/rails/rails/issues/9994

thanks to @dsabanin for reporting the regression and for creating
failing gist