assert_template... what's the reasoning for looking at the first rendered file?

Hello,

In actionpack/lib/action_controller/test_process.rb

Why does the following method, use the first rendered file and not the last?

# returns the template path of the file which was used to
# render this response (or nil)
def rendered_file(with_controller=false)
  unless template.first_render.nil?
    unless with_controller
      template.first_render
    else
      template.first_render.split('/').last || template.first_render
    end
  end
end

  Currently I'm using assert_template which calls this method and I do
a render_to_string in the action I'm testing before the actions view
is rendered, so assert_template is saying the template that's being
rendered is the one from render_to_string, which is not what I want.
Is it looking at the first rendered file because the last file could
be a partial rendered in the view for example?

eg.

def my_action
  @code = render_to_string :partial => 'blah'
  render :action => 'other_action'
end

assert_template says the rendered template is 'blah' and not 'other_action'.

Is this a bug in assert_template? I would think it should ignore the
file being rendered from render_to_string.

Thanks,
Andrew

I've wrestled with the same problem. I first render one of several
templates to a string, then include the string within a rendered
template. And my testing breaks (or at least is counter-intuitive) as
well.

It certainly doesn't seem right that rendering to a string dominates
(assert_template-wise) the rendering of a template for CGI. And it
also doesn't seem right that the first render action dominates the
last render action.

Anybody got a good explanation for this strange behavior?

-Chris

I've wrestled with the same problem. I first render one of several
templates to a string, then include the string within a rendered
template. And my testing breaks (or at least is counter-intuitive) as
well.

It certainly doesn't seem right that rendering to a string dominates
(assert_template-wise) the rendering of a template for CGI. And it
also doesn't seem right that the first render action dominates the
last render action.

Anybody got a good explanation for this strange behavior?

-Chris

We've just run into this problem ourselves, when playing with the
idea of separating the flash messages into their own files.

Not to pass the buck, but would someone be able to produce a patch
that
changed the behavior of rendered_file to return the last file
rendered? I don't
readily see a reason for Core to refuse it.

Tammer

I'll see if I can come with a patch soon. I took a quick glance at
the code, but I didn't see an obvious fix. I only spent about 10-15
mins looking though.

Andrew