Andrew Kaspick
2007-Jun-13 23:20 UTC
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Chris Cruft
2007-Jun-14 13:12 UTC
Re: assert_template... what''s the reasoning for looking at the first rendered file?
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 On Jun 13, 7:20 pm, "Andrew Kaspick" <akasp...@gmail.com> wrote:> 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--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Chris Cruft
2007-Jun-14 13:14 UTC
Re: assert_template... what''s the reasoning for looking at the first rendered file?
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 On Jun 13, 7:20 pm, "Andrew Kaspick" <akasp...@gmail.com> wrote:> 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--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Tammer Saleh
2007-Jun-15 13:14 UTC
Re: assert_template... what''s the reasoning for looking at the first rendered file?
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 On Jun 14, 9:14 am, Chris Cruft <c...@hapgoods.com> wrote:> 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 > > On Jun 13, 7:20 pm, "Andrew Kaspick" <akasp...@gmail.com> wrote: > > > 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--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Andrew Kaspick
2007-Jun-18 09:18 UTC
Re: assert_template... what''s the reasoning for looking at the first rendered file?
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 On 6/15/07, Tammer Saleh <tsaleh@gmail.com> wrote:> > 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 > > On Jun 14, 9:14 am, Chris Cruft <c...@hapgoods.com> wrote: > > 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 > > > > On Jun 13, 7:20 pm, "Andrew Kaspick" <akasp...@gmail.com> wrote: > > > > > 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 > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---