mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Adding Rails.env= to railties to allow changing of rails env on the fly for rake tasks etc
Signed-off-by: José Valim <jose.valim@gmail.com>
This commit is contained in:
committed by
José Valim
parent
6891f46d10
commit
336cb3c0bf
@@ -79,6 +79,10 @@ module Rails
|
||||
@_env ||= ActiveSupport::StringInquirer.new(ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development")
|
||||
end
|
||||
|
||||
def env=(environment)
|
||||
@_env = ActiveSupport::StringInquirer.new(environment)
|
||||
end
|
||||
|
||||
def cache
|
||||
RAILS_CACHE
|
||||
end
|
||||
|
||||
@@ -125,5 +125,16 @@ module RailtiesTest
|
||||
require "#{app_path}/config/environment"
|
||||
assert $ran_block
|
||||
end
|
||||
|
||||
test "we can change our environment if we want to" do
|
||||
begin
|
||||
original_env = Rails.env
|
||||
Rails.env = 'foo'
|
||||
assert_equal('foo', Rails.env)
|
||||
ensure
|
||||
Rails.env = original_env
|
||||
assert_equal(original_env, Rails.env)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user