aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRick Olson <technoweenie@gmail.com>2007-08-15 18:59:37 +0000
committerRick Olson <technoweenie@gmail.com>2007-08-15 18:59:37 +0000
commit0127e586d05f3e8342744608315747da488642eb (patch)
tree3f3658068188de642cbaeb648033d74996e26f60
parentd0c83c435459b3fff53075a84411f39707f31325 (diff)
downloadrails-0127e586d05f3e8342744608315747da488642eb.tar.gz
rails-0127e586d05f3e8342744608315747da488642eb.tar.bz2
rails-0127e586d05f3e8342744608315747da488642eb.zip
Find layouts even if they're not in the first view_paths directory. Closes #9258 [caio]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7321 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/lib/action_controller/layout.rb8
-rw-r--r--actionpack/test/controller/view_paths_test.rb15
3 files changed, 19 insertions, 6 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index ce720ca72d..56ce3e1095 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Find layouts even if they're not in the first view_paths directory. Closes #9258 [caio]
+
* Major improvement to the documentation for the options / select form helpers. Closes #9038 [kampers, jardeon, wesg]
* Fix number_to_human_size when using different precisions. Closes #7536. [RichardStrand, mpalmer]
diff --git a/actionpack/lib/action_controller/layout.rb b/actionpack/lib/action_controller/layout.rb
index 860d7b383c..027ae42aeb 100644
--- a/actionpack/lib/action_controller/layout.rb
+++ b/actionpack/lib/action_controller/layout.rb
@@ -307,12 +307,10 @@ module ActionController #:nodoc:
# Does a layout directory for this class exist?
# we cache this info in a class level hash
def layout_directory?(layout_name)
- view_paths.find do |path|
- File.file?(File.join(path, 'layouts', layout_name))
+ view_paths.find do |path|
+ next unless template_path = Dir[File.join(path, 'layouts', layout_name) + ".*"].first
+ self.class.send(:layout_directory_exists_cache)[File.dirname(template_path)]
end
- template_path ||= File.join(view_paths.first, 'layouts', layout_name)
- dirname = File.dirname(template_path)
- self.class.send(:layout_directory_exists_cache)[dirname]
end
end
end
diff --git a/actionpack/test/controller/view_paths_test.rb b/actionpack/test/controller/view_paths_test.rb
index d6d6dac4f3..c84ced5394 100644
--- a/actionpack/test/controller/view_paths_test.rb
+++ b/actionpack/test/controller/view_paths_test.rb
@@ -18,6 +18,11 @@ class ViewLoadPathsTest < Test::Unit::TestCase
end
end
+ class Test::SubController < ActionController::Base
+ layout 'test/sub'
+ def hello_world; render 'test/hello_world'; end
+ end
+
def setup
TestController.view_paths = [ LOAD_PATH_ROOT ]
@controller = TestController.new
@@ -27,7 +32,7 @@ class ViewLoadPathsTest < Test::Unit::TestCase
# Track the last warning.
@old_behavior = ActiveSupport::Deprecation.behavior
@last_message = nil
- ActiveSupport::Deprecation.behavior = Proc.new { |message| @last_message = message }
+ ActiveSupport::Deprecation.behavior = Proc.new { |message, callback| @last_message = message }
end
def teardown
@@ -51,6 +56,14 @@ class ViewLoadPathsTest < Test::Unit::TestCase
assert_equal "Hello overridden world!", @response.body
end
+ def test_view_paths_override_for_layouts_in_controllers_with_a_module
+ @controller = Test::SubController.new
+ Test::SubController.view_paths = [ "#{LOAD_PATH_ROOT}/override", LOAD_PATH_ROOT, "#{LOAD_PATH_ROOT}/override2" ]
+ get :hello_world
+ assert_response :success
+ assert_equal "layout: Hello overridden world!", @response.body
+ end
+
def test_view_paths_override_at_request_time
get :hello_world_at_request_time
assert_response :success