Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Prevent assert_template failures when a render :inline is called befo…

…re rendering a file-based template [#1383 state:resolved]

Signed-off-by: Joshua Peek <josh@joshpeek.com>
  • Loading branch information...
commit f7a8e394008f62e8f07874f6c679e10c40e8de57 1 parent 76b54c5
@lukemelia lukemelia authored josh committed
View
4 actionpack/lib/action_view/renderable.rb
@@ -29,7 +29,9 @@ def render(view, local_assigns = {})
stack.push(self)
# This is only used for TestResponse to set rendered_template
- view.instance_variable_set(:@_first_render, self) unless view.instance_variable_get(:@_first_render)
+ unless is_a?(InlineTemplate) || view.instance_variable_get(:@_first_render)
+ view.instance_variable_set(:@_first_render, self)
+ end
view.send(:_evaluate_assigns_and_ivars)
view.send(:_set_controller_content_type, mime_type) if respond_to?(:mime_type)
View
28 actionpack/test/controller/render_test.rb
@@ -39,7 +39,7 @@ def conditional_hello_with_bangs
render :action => 'hello_world'
end
before_filter :handle_last_modified_and_etags, :only=>:conditional_hello_with_bangs
-
+
def handle_last_modified_and_etags
fresh_when(:last_modified => Time.now.utc.beginning_of_day, :etag => [ :foo, 123 ])
end
@@ -337,6 +337,11 @@ def render_to_string_and_render
render :text => "Hi web users! #{@stuff}"
end
+ def render_to_string_with_inline_and_render
+ render_to_string :inline => "<%= 'dlrow olleh'.reverse %>"
+ render :template => "test/hello_world"
+ end
+
def rendering_with_conflicting_local_vars
@name = "David"
def @template.name() nil end
@@ -908,6 +913,11 @@ def test_render_to_string_resets_assigns
assert_equal "The value of foo is: ::this is a test::\n", @response.body
end
+ def test_render_to_string_inline
+ get :render_to_string_with_inline_and_render
+ assert_template "test/hello_world"
+ end
+
def test_nested_rendering
@controller = Fun::GamesController.new
get :hello_world
@@ -1368,7 +1378,7 @@ def test_render_against_etag_request_should_200_when_no_match
assert_equal "200 OK", @response.status
assert !@response.body.empty?
end
-
+
def test_render_should_not_set_etag_when_last_modified_has_been_specified
get :render_hello_world_with_last_modified_set
assert_equal "200 OK", @response.status
@@ -1382,7 +1392,7 @@ def test_render_with_etag
expected_etag = etag_for('hello david')
assert_equal expected_etag, @response.headers['ETag']
@response = ActionController::TestResponse.new
-
+
@request.if_none_match = expected_etag
get :render_hello_world_from_variable
assert_equal "304 Not Modified", @response.status
@@ -1407,24 +1417,24 @@ def test_etag_should_govern_renders_with_layouts_too
assert_equal "<wrapper>\n<html>\n <p>Hello </p>\n<p>This is grand!</p>\n</html>\n</wrapper>\n", @response.body
assert_equal etag_for("<wrapper>\n<html>\n <p>Hello </p>\n<p>This is grand!</p>\n</html>\n</wrapper>\n"), @response.headers['ETag']
end
-
+
def test_etag_with_bang_should_set_etag
get :conditional_hello_with_bangs
assert_equal @expected_bang_etag, @response.headers["ETag"]
assert_response :success
end
-
+
def test_etag_with_bang_should_obey_if_none_match
@request.if_none_match = @expected_bang_etag
get :conditional_hello_with_bangs
assert_response :not_modified
end
-
+
protected
def etag_for(text)
%("#{Digest::MD5.hexdigest(text)}")
end
-
+
def expand_key(args)
ActiveSupport::Cache.expand_cache_key(args)
end
@@ -1467,13 +1477,13 @@ def test_request_modified
assert !@response.body.blank?
assert_equal @last_modified, @response.headers['Last-Modified']
end
-
+
def test_request_with_bang_gets_last_modified
get :conditional_hello_with_bangs
assert_equal @last_modified, @response.headers['Last-Modified']
assert_response :success
end
-
+
def test_request_with_bang_obeys_last_modified
@request.if_modified_since = @last_modified
get :conditional_hello_with_bangs
Please sign in to comment.
Something went wrong with that request. Please try again.