diff options
author | Rick Olson <technoweenie@gmail.com> | 2007-02-04 20:47:05 +0000 |
---|---|---|
committer | Rick Olson <technoweenie@gmail.com> | 2007-02-04 20:47:05 +0000 |
commit | 69b0e5c44a05fddcac996c7aaaca61cb3188da5e (patch) | |
tree | 4e5da68ffe3eac5561a9101a451a2f56a701e989 /actionpack/test/controller/view_paths_test.rb | |
parent | 8f614a80e725228c0cc0c03fd731c6cbad0ffcb7 (diff) | |
download | rails-69b0e5c44a05fddcac996c7aaaca61cb3188da5e.tar.gz rails-69b0e5c44a05fddcac996c7aaaca61cb3188da5e.tar.bz2 rails-69b0e5c44a05fddcac996c7aaaca61cb3188da5e.zip |
Allow Controllers to have multiple view_paths instead of a single template_root. Closes #2754 [John Long]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6120 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/test/controller/view_paths_test.rb')
-rw-r--r-- | actionpack/test/controller/view_paths_test.rb | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/actionpack/test/controller/view_paths_test.rb b/actionpack/test/controller/view_paths_test.rb new file mode 100644 index 0000000000..9184ab1793 --- /dev/null +++ b/actionpack/test/controller/view_paths_test.rb @@ -0,0 +1,78 @@ +require File.dirname(__FILE__) + '/../abstract_unit' + +class ViewLoadPathsTest < Test::Unit::TestCase + + LOAD_PATH_ROOT = File.join(File.dirname(__FILE__), '..', 'fixtures') + + class TestController < ActionController::Base + def self.controller_path() "test" end + def rescue_action(e) raise end + + def hello_world() end + end + + def setup + TestController.view_paths = [ LOAD_PATH_ROOT ] + @controller = TestController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + + # Track the last warning. + @old_behavior = ActiveSupport::Deprecation.behavior + @last_message = nil + ActiveSupport::Deprecation.behavior = Proc.new { |message| @last_message = message } + end + + def teardown + ActiveSupport::Deprecation.behavior = @old_behavior + end + + def test_template_load_path_was_set_correctly + assert_equal [ LOAD_PATH_ROOT ], @controller.view_paths + end + + def test_view_paths + get :hello_world + assert_response :success + assert_equal "Hello world!", @response.body + end + + def test_view_paths_override + TestController.view_paths.unshift "#{LOAD_PATH_ROOT}/override" + get :hello_world + assert_response :success + assert_equal "Hello overridden world!", @response.body + end + + def test_template_root_deprecated + assert_deprecated(/template_root.*view_paths/) do + TestController.template_root = LOAD_PATH_ROOT + end + assert_deprecated(/template_root.*view_paths/) do + assert_equal LOAD_PATH_ROOT, TestController.template_root + end + end + + def test_inheritance + original_load_paths = ActionController::Base.view_paths + + self.class.class_eval %{ + class A < ActionController::Base; end + class B < A; end + class C < ActionController::Base; end + } + + A.view_paths = [ 'a/path' ] + + assert_equal [ 'a/path' ], A.view_paths + assert_equal A.view_paths, B.view_paths + assert_equal original_load_paths, C.view_paths + + e = assert_raises(TypeError) { C.view_paths << 'c/path' } + assert_equal "can't modify frozen array", e.message + + C.view_paths = [] + assert_nothing_raised { C.view_paths << 'c/path' } + end + +end
\ No newline at end of file |