Changeset 8035
- Timestamp:
- 10/26/07 05:45:41 (10 months ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_controller/base.rb (modified) (3 diffs)
- trunk/actionpack/test/controller/view_paths_test.rb (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r8034 r8035 1 1 *SVN* 2 3 * Simplfy #view_paths implementation. ActionView templates get the exact object, not a dup. [Rick] 2 4 3 5 * Update tests for ActiveSupport's JSON escaping change. [rick] trunk/actionpack/lib/action_controller/base.rb
r8011 r8035 409 409 end 410 410 411 412 @@view_paths = {} 413 414 # View load paths determine the bases from which template references can be made. So a call to 415 # render("test/template") will be looked up in the view load paths array and the closest match will be 416 # returned. 411 ## View load paths determine the bases from which template references can be made. So a call to 412 ## render("test/template") will be looked up in the view load paths array and the closest match will be 413 ## returned. 414 def view_paths 415 @view_paths || superclass.view_paths 416 end 417 417 418 def view_paths=(value) 418 @@view_paths[name] = value 419 end 420 421 # View load paths for controller. 422 def view_paths 423 if paths = @@view_paths[name] 424 paths 425 else 426 if superclass.respond_to?(:view_paths) 427 superclass.view_paths.dup.freeze 428 else 429 @@view_paths[name] = [] 430 end 431 end 432 end 433 419 @view_paths = value 420 end 421 434 422 # Adds a view_path to the front of the view_paths array. 435 423 # If the current class has no view paths, copy them from 436 424 # the superclass 425 # 426 # ArticleController.prepend_view_path("views/default") 427 # ArticleController.prepend_view_path(["views/default", "views/custom"]) 428 # 437 429 def prepend_view_path(path) 438 self.view_paths = view_paths.dup if view_paths.frozen?439 view_paths.unshift( path)430 @view_paths = superclass.view_paths.dup if @view_paths.nil? 431 view_paths.unshift(*path) 440 432 end 441 433 … … 443 435 # If the current class has no view paths, copy them from 444 436 # the superclass 437 # 438 # ArticleController.append_view_path("views/default") 439 # ArticleController.append_view_path(["views/default", "views/custom"]) 440 # 445 441 def append_view_path(path) 446 self.view_paths = view_paths.dup if view_paths.frozen?447 view_paths << path442 @view_paths = superclass.view_paths.dup if @view_paths.nil? 443 view_paths.push(*path) 448 444 end 449 445 … … 632 628 end 633 629 630 631 self.view_paths = [] 632 634 633 # View load paths for controller. 635 634 def view_paths 636 self.class.view_paths 635 (@template || self.class).view_paths 636 end 637 638 def view_paths=(value) 639 (@template || self.class).view_paths = value 637 640 end 638 641 trunk/actionpack/test/controller/view_paths_test.rb
r7426 r8035 4 4 5 5 LOAD_PATH_ROOT = File.join(File.dirname(__FILE__), '..', 'fixtures') 6 7 ActionController::Base.view_paths = [ LOAD_PATH_ROOT ] 6 8 7 9 class TestController < ActionController::Base … … 25 27 26 28 def setup 27 TestController.view_paths = [ LOAD_PATH_ROOT ]29 TestController.view_paths = nil 28 30 @controller = TestController.new 29 31 @request = ActionController::TestRequest.new … … 42 44 def test_template_load_path_was_set_correctly 43 45 assert_equal [ LOAD_PATH_ROOT ], @controller.view_paths 46 end 47 48 def test_template_appends_path_correctly 49 TestController.append_view_path 'foo' 50 assert_equal [LOAD_PATH_ROOT, 'foo'], @controller.view_paths 51 52 TestController.append_view_path(%w(bar baz)) 53 assert_equal [LOAD_PATH_ROOT, 'foo', 'bar', 'baz'], @controller.view_paths 54 end 55 56 def test_template_prepends_path_correctly 57 TestController.prepend_view_path 'baz' 58 assert_equal ['baz', LOAD_PATH_ROOT], @controller.view_paths 59 60 TestController.prepend_view_path(%w(foo bar)) 61 assert_equal ['foo', 'bar', 'baz', LOAD_PATH_ROOT], @controller.view_paths 44 62 end 45 63 … … 86 104 assert_equal original_load_paths, C.view_paths 87 105 88 e = assert_raises(TypeError) { C.view_paths << 'c/path' }89 assert_equal "can't modify frozen array", e.message90 91 106 C.view_paths = [] 92 107 assert_nothing_raised { C.view_paths << 'c/path' } 108 assert_equal ['c/path'], C.view_paths 93 109 end 94 110