Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #4632 (closed defect: fixed)

Opened 3 years ago

Last modified 2 years ago

[PATCH] Problem with render_component and integration tests

Reported by: dev.rubyonrails@maxdunn.com Assigned to: David
Priority: normal Milestone: 1.2
Component: ActionPack Version: 1.1.0
Severity: major Keywords: render_component integration tests
Cc:

Description

The new integration tests looked like a good way to test render_component actions, which was not possible with normal functional tests. However, when trying this, render_component would use the controller it was called from and not the one specified.

For example, I am using render_component in an Instiki page to display an event schedule. So even though render_component was correctly using EventsController in real use, when the same code was executed from an ActionController::IntegrationTest class, render_component was incorrectly using WikiController.

The problem it turns out was that new_with_capture in integration.rb was caching the last controller:

  self.last_instantiation ||= new_without_capture(*args) 

The fix is to add a check that the class of the last controller is the same as the one we are creating.

Attachments

render_component_integration_test.patch (0.8 kB) - added by dev.rubyonrails@maxdunn.com on 04/06/06 21:58:05.
wiki_event_test.rb (3.9 kB) - added by dev.rubyonrails@maxdunn.com on 06/02/06 19:27:20.
Sample integration test
integration_render_component_fix.patch (0.5 kB) - added by edward.frederick@revolution.com on 06/26/06 14:12:16.
Patch for fixing render_component in integration tests.

Change History

04/06/06 21:58:05 changed by dev.rubyonrails@maxdunn.com

  • attachment render_component_integration_test.patch added.

04/07/06 00:30:59 changed by dev.rubyonrails@maxdunn.com

Here is an example of how render_component is needed to show a schedule in a Instiki page:

http://tricitiesbaseball.org/tric/show/Majors-Giants

05/31/06 11:32:21 changed by lovecider@gmail.com

The patch here is not working. Still seeing this bug.

06/02/06 19:25:20 changed by dev.rubyonrails@maxdunn.com

How were you testing this and with what version? Do you have an integration test you can post?

I don't have a generic integration test for this; the one I use is dependent on my heavily customized code so it wouldn't be much use outside my environment. However, for what it is worth, I will attach it.

Here is an updated link showing an example of this:

http://tricitiesbaseball.org/tric/show/Majors-Giants

06/02/06 19:27:20 changed by dev.rubyonrails@maxdunn.com

  • attachment wiki_event_test.rb added.

Sample integration test

06/07/06 13:51:42 changed by tvollmer@codemart.de

The bug still remains: I digged a little bit and found that the LAST used controller is always used for the response in process(). If you use render_component() once or even multiple times you will get that controller as response. You will even get the body of that action as response and not the whole response. Bad. I am not sure how to fix that. The whole treatment in process() (extending and changing new_with_capture must be done differently. Anyone?

06/07/06 14:38:39 changed by tvollmer@codemart.de

Maybe some more information how this happens:

- call render_component() from a layout into a controller, like a sidebar or something

06/26/06 14:10:14 changed by edward.frederick@revolution.com

  • severity changed from normal to major.

As written, the integration testing code allows one and only one controller to be instantiated during the course of a request (due to the =). When no components are being rendered, this is fine (as only one controller is going to be instantiated anyway.)

I could be wrong, but I don't think the capture method meant to be doing any 'caching', so the check in the first patch may not be needed or desirable. In addition, the last controller response will be returned as the 'real' response, which is definitely not what you want when a controller is rendering other components.

By returning the response of the first controller that was instantiated (rather than the last), you get the 'real' response complete with aggregate body from any intermediate render_components. This is what this baby patch does.

06/26/06 14:12:16 changed by edward.frederick@revolution.com

  • attachment integration_render_component_fix.patch added.

Patch for fixing render_component in integration tests.

07/08/06 00:18:24 changed by bitsweat

  • milestone changed from 1.1 to 1.2.

07/08/06 00:18:43 changed by bitsweat

  • status changed from new to closed.
  • resolution set to fixed.

(In [4582]) Integration tests behave well with render_component. Closes #4632.

07/08/06 04:16:54 changed by anonymous

  • summary changed from hi-world cup to [PATCH] Problem with render_component and integration tests.

07/08/06 04:18:18 changed by dev.rubyonrails@maxdunn.com

  • keywords changed from rthml tab space editor js to render_component integration tests.

Just backing out the spam...