Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
lukemelia authored and josh committed Nov 18, 2008
1 parent 76b54c5 commit f7a8e39
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
4 changes: 3 additions & 1 deletion actionpack/lib/action_view/renderable.rb
Expand Up @@ -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)
Expand Down
28 changes: 19 additions & 9 deletions actionpack/test/controller/render_test.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f7a8e39

Please sign in to comment.