Add test for #16622 as of a6de6f5

cc @chancancode 
What about to use [switch_env](https://github.com/rails/rails/blob/master/railties/test/env_helpers.rb#L24) block here to set it back after test?