updated checks of environment with Rails.env by Rails.env methods
updated test with proper change of Rails.env during test
Merge pull request #2665 from akshaymohite/optimization-fixes

updated checks of environment with Rails.env by Rails.env methods