From 420c4b3d8878156d04f45e47050ddc62ae00c68c Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 13 Apr 2008 17:33:27 -0500 Subject: Added Rails.public_path to control where HTML and assets are expected to be loaded from (defaults to Rails.root + "/public") #11581 [nicksieger] --- actionpack/test/controller/rescue_test.rb | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'actionpack/test/controller/rescue_test.rb') diff --git a/actionpack/test/controller/rescue_test.rb b/actionpack/test/controller/rescue_test.rb index 55631e0777..011992474f 100644 --- a/actionpack/test/controller/rescue_test.rb +++ b/actionpack/test/controller/rescue_test.rb @@ -305,7 +305,9 @@ class RescueTest < Test::Unit::TestCase def test_not_implemented with_all_requests_local false do - head :not_implemented + with_rails_public_path(".") do + head :not_implemented + end end assert_response :not_implemented assert_equal "GET, PUT", @response.headers['Allow'] @@ -313,7 +315,9 @@ class RescueTest < Test::Unit::TestCase def test_method_not_allowed with_all_requests_local false do - get :method_not_allowed + with_rails_public_path(".") do + get :method_not_allowed + end end assert_response :method_not_allowed assert_equal "GET, HEAD, PUT", @response.headers['Allow'] @@ -391,7 +395,19 @@ class RescueTest < Test::Unit::TestCase @request.remote_addr = old_remote_addr end - def with_rails_root(path = nil) + def with_rails_public_path(rails_root) + old_rails = Object.const_get(:Rails) rescue nil + mod = Object.const_set(:Rails, Module.new) + (class << mod; self; end).instance_eval do + define_method(:public_path) { "#{rails_root}/public" } + end + yield + ensure + Object.module_eval { remove_const(:Rails) } if defined?(Rails) + Object.const_set(:Rails, old_rails) if old_rails + end + + def with_rails_root(path = nil,&block) old_rails_root = RAILS_ROOT if defined?(RAILS_ROOT) if path silence_warnings { Object.const_set(:RAILS_ROOT, path) } @@ -399,7 +415,7 @@ class RescueTest < Test::Unit::TestCase Object.remove_const(:RAILS_ROOT) rescue nil end - yield + with_rails_public_path(path, &block) ensure if old_rails_root -- cgit v1.2.3