Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding Rails.env= to railties to allow changing of rails env on the f…

…ly for rake tasks etc

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
commit 336cb3c0bf3d38400f6c774ca78376117b899985 1 parent 6891f46
@mikel mikel authored josevalim committed
Showing with 15 additions and 0 deletions.
  1. +4 −0 railties/lib/rails.rb
  2. +11 −0 railties/test/railties/railtie_test.rb
View
4 railties/lib/rails.rb
@@ -79,6 +79,10 @@ def env
@_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
View
11 railties/test/railties/railtie_test.rb
@@ -125,5 +125,16 @@ class MyTie < Rails::Railtie
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
Please sign in to comment.
Something went wrong with that request. Please try again.