aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-10-14 09:27:18 +0200
committerJosé Valim <jose.valim@gmail.com>2010-10-14 09:27:18 +0200
commit37d78028b235f04b2d3ca5cd88b7e1e0ad218684 (patch)
treed89694e106cbc3353ac1b0eeaf257ea91b3a7b01
parentc7aea81a39e130bfddd26537dea5f3626e2a009e (diff)
downloadrails-37d78028b235f04b2d3ca5cd88b7e1e0ad218684.tar.gz
rails-37d78028b235f04b2d3ca5cd88b7e1e0ad218684.tar.bz2
rails-37d78028b235f04b2d3ca5cd88b7e1e0ad218684.zip
render :once should consider the current controller prefix.
-rw-r--r--actionpack/lib/action_view/base.rb4
-rw-r--r--actionpack/lib/action_view/renderer/partial_renderer.rb4
-rw-r--r--actionpack/lib/action_view/renderer/template_renderer.rb3
-rw-r--r--actionpack/test/controller/new_base/render_once_test.rb37
-rw-r--r--actionpack/test/template/log_subscriber_test.rb6
5 files changed, 41 insertions, 13 deletions
diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb
index a7a6bbd3a4..1beae37af3 100644
--- a/actionpack/lib/action_view/base.rb
+++ b/actionpack/lib/action_view/base.rb
@@ -224,6 +224,10 @@ module ActionView #:nodoc:
@controller_path ||= controller && controller.controller_path
end
+ def controller_prefix
+ @controller_prefix ||= controller && controller._prefix
+ end
+
ActiveSupport.run_load_hooks(:action_view, self)
end
end
diff --git a/actionpack/lib/action_view/renderer/partial_renderer.rb b/actionpack/lib/action_view/renderer/partial_renderer.rb
index eff425687b..c580397cad 100644
--- a/actionpack/lib/action_view/renderer/partial_renderer.rb
+++ b/actionpack/lib/action_view/renderer/partial_renderer.rb
@@ -110,7 +110,7 @@ module ActionView
end
def find_template(path=@path, locals=@locals.keys)
- prefix = @view.controller_path unless path.include?(?/)
+ prefix = @view.controller_prefix unless path.include?(?/)
@lookup_context.find_template(path, prefix, true, locals)
end
@@ -151,7 +151,7 @@ module ActionView
object = object.to_model if object.respond_to?(:to_model)
object.class.model_name.partial_path.dup.tap do |partial|
- path = @view.controller_path
+ path = @view.controller_prefix
partial.insert(0, "#{File.dirname(path)}/") if partial.include?(?/) && path.include?(?/)
end
end
diff --git a/actionpack/lib/action_view/renderer/template_renderer.rb b/actionpack/lib/action_view/renderer/template_renderer.rb
index a9076760c5..34b2f26199 100644
--- a/actionpack/lib/action_view/renderer/template_renderer.rb
+++ b/actionpack/lib/action_view/renderer/template_renderer.rb
@@ -21,7 +21,8 @@ module ActionView
def render_once(options)
paths, locals = options[:once], options[:locals] || {}
- layout, keys, prefix = options[:layout], locals.keys, options[:prefix]
+ layout, keys = options[:layout], locals.keys
+ prefix = options.fetch(:prefix, @view.controller_prefix)
raise "render :once expects a String or an Array to be given" unless paths
diff --git a/actionpack/test/controller/new_base/render_once_test.rb b/actionpack/test/controller/new_base/render_once_test.rb
index 63de25be52..3a847ac932 100644
--- a/actionpack/test/controller/new_base/render_once_test.rb
+++ b/actionpack/test/controller/new_base/render_once_test.rb
@@ -8,29 +8,42 @@ module RenderTemplate
"test/a.html.erb" => "a",
"test/b.html.erb" => "<>",
"test/c.html.erb" => "c",
- "test/one.html.erb" => "<%= render :once => 'test/result' %>",
- "test/two.html.erb" => "<%= render :once => 'test/result' %>",
- "test/three.html.erb" => "<%= render :once => 'test/result' %>",
+ "test/one.html.erb" => "<%= render :once => 'result' %>",
+ "test/two.html.erb" => "<%= render :once => 'result' %>",
+ "test/three.html.erb" => "<%= render :once => 'result' %>",
"test/result.html.erb" => "YES!",
+ "other/result.html.erb" => "NO!",
"layouts/test.html.erb" => "l<%= yield %>l"
)
self.view_paths = [RESOLVER]
+ def _prefix
+ "test"
+ end
+
def multiple
- render :once => %w(test/a test/b test/c)
+ render :once => %w(a b c)
end
def once
- render :once => %w(test/one test/two test/three)
+ render :once => %w(one two three)
end
def duplicate
- render :once => %w(test/a test/a test/a)
+ render :once => %w(a a a)
end
def with_layout
- render :once => %w(test/a test/b test/c), :layout => "test"
+ render :once => %w(a b c), :layout => "test"
+ end
+
+ def with_prefix
+ render :once => "result", :prefix => "other"
+ end
+
+ def with_nil_prefix
+ render :once => "test/result", :prefix => nil
end
end
@@ -54,6 +67,16 @@ module RenderTemplate
get :with_layout
assert_response "la\n<>\ncl"
end
+
+ def test_with_prefix_option
+ get :with_prefix
+ assert_response "NO!"
+ end
+
+ def test_with_nil_prefix_option
+ get :with_nil_prefix
+ assert_response "YES!"
+ end
end
class TestWithResolverCache < Rack::TestCase
diff --git a/actionpack/test/template/log_subscriber_test.rb b/actionpack/test/template/log_subscriber_test.rb
index 6fb8d39818..435936b19f 100644
--- a/actionpack/test/template/log_subscriber_test.rb
+++ b/actionpack/test/template/log_subscriber_test.rb
@@ -57,7 +57,7 @@ class AVLogSubscriberTest < ActiveSupport::TestCase
end
def test_render_partial_with_implicit_path
- @view.stubs(:controller_path).returns("test")
+ @view.stubs(:controller_prefix).returns("test")
@view.render(Customer.new("david"), :greeting => "hi")
wait
@@ -74,7 +74,7 @@ class AVLogSubscriberTest < ActiveSupport::TestCase
end
def test_render_collection_with_implicit_path
- @view.stubs(:controller_path).returns("test")
+ @view.stubs(:controller_prefix).returns("test")
@view.render([ Customer.new("david"), Customer.new("mary") ], :greeting => "hi")
wait
@@ -83,7 +83,7 @@ class AVLogSubscriberTest < ActiveSupport::TestCase
end
def test_render_collection_template_without_path
- @view.stubs(:controller_path).returns("test")
+ @view.stubs(:controller_prefix).returns("test")
@view.render([ GoodCustomer.new("david"), Customer.new("mary") ], :greeting => "hi")
wait