Dont use Rails.env before require rails/all
Dont use Rails.env before require rails/all

On rails 4.0+ , when calling Rails.env that will be memoized https://github.com/rails/rails/blob/4-0-stable/railties/lib/rails.rb#L56 , so if RAILS_ENV changes after that, for instance for tests https://github.com/rails/rails/commit/3ff263919c67588e4348da30cb92b860fe83cba5 that @_env ivar will have the wrong value.

Solution is not use Rails.env before requiring all rails

JuanitoFatas/rubygems.org,farukaydin/rubygems.org,arthurnn/rubygems.org,Exeia/rubygems.org,childbamboo/rubygems.org,algolia/rubygems.org,maclover7/rubygems.org,knappe/rubygems.org,andrew/rubygems.org,iSC-Labs/rubygems.org,wallin/rubygems.org,huacnlee/rubygems.org,iRoxxDotOrg/rubygems.org,olivierlacan/rubygems.org,andrew/rubygems.org,Ch4s3/rubygems.org,hrs113355/rubygems.org,jamelablack/rubygems.org,farukaydin/rubygems.org,jamelablack/rubygems.org,childbamboo/rubygems.org,arthurnn/rubygems.org,kbrock/rubygems.org,fotanus/rubygems.org,sonalkr132/rubygems.org,JuanitoFatas/rubygems.org,maclover7/rubygems.org,algolia/rubygems.org,iRoxxDotOrg/rubygems.org,arthurnn/rubygems.org,knappe/rubygems.org,Elffers/rubygems.org,maclover7/rubygems.org,krainboltgreene/rubygems.org,sonalkr132/rubygems.org,olivierlacan/rubygems.org,Elffers/rubygems.org,wallin/rubygems.org,huacnlee/rubygems.org,sonalkr132/rubygems.org,krainboltgreene/rubygems.org,algolia/rubygems.org,knappe/rubygems.org,davydovanton/rubygems.org,Ch4s3/rubygems.org,jamelablack/rubygems.org,Elffers/rubygems.org,iSC-Labs/rubygems.org,andrew/rubygems.org,farukaydin/rubygems.org,Ch4s3/rubygems.org,rubygems/rubygems.org,iSC-Labs/rubygems.org,iSC-Labs/rubygems.org,farukaydin/rubygems.org,rubygems/rubygems.org,sonalkr132/rubygems.org,kbrock/rubygems.org,Exeia/rubygems.org,rubygems/rubygems.org,huacnlee/rubygems.org,davydovanton/rubygems.org,Elffers/rubygems.org,fotanus/rubygems.org,polamjag/rubygems.org,rubygems/rubygems.org,polamjag/rubygems.org,krainboltgreene/rubygems.org,wallin/rubygems.org,krainboltgreene/rubygems.org,polamjag/rubygems.org,knappe/rubygems.org,andrew/rubygems.org,iRoxxDotOrg/rubygems.org,hrs113355/rubygems.org,polamjag/rubygems.org,jamelablack/rubygems.org,iRoxxDotOrg/rubygems.org,spk/rubygems.org,spk/rubygems.org,maclover7/rubygems.org,childbamboo/rubygems.org,davydovanton/rubygems.org,huacnlee/rubygems.org,fotanus/rubygems.org,JuanitoFatas/rubygems.org,spk/rubygems.org,hrs113355/rubygems.org,kbrock/rubygems.org,Ch4s3/rubygems.org,childbamboo/rubygems.org,hrs113355/rubygems.org,wallin/rubygems.org,fotanus/rubygems.org,Exeia/rubygems.org,davydovanton/rubygems.org,olivierlacan/rubygems.org,JuanitoFatas/rubygems.org,olivierlacan/rubygems.org,spk/rubygems.org,algolia/rubygems.org,Exeia/rubygems.org,kbrock/rubygems.org