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

Ticket #10382 (closed defect: fixed)

Opened 8 months ago

Last modified 3 months ago

[PATCH] Don't let setup methods in ActionController::TestCase be overridden

Reported by: josh Assigned to: michael@koziarski.com
Priority: normal Milestone: 2.x
Component: ActionPack Version: edge
Severity: normal Keywords: verified
Cc:

Description

Uses the same technique as setup_with_fixtures to ensure that the controller methods are always setup.

http://quotedprintable.com/2007/12/5/potential-gotcha-with-test-setup-in-rails-2-0/comments/778

Attachments

dont_let_setup_with_controller_be_overridden.diff (1.7 kB) - added by josh on 12/05/07 21:38:19.

Change History

12/05/07 21:38:19 changed by josh

  • attachment dont_let_setup_with_controller_be_overridden.diff added.

12/05/07 21:49:20 changed by packagethief

+1. That was fast, Josh.

12/06/07 09:59:16 changed by jaw6

+1, very spiffy

12/06/07 10:10:49 changed by winstondesign

+1

12/06/07 10:50:57 changed by chuyeow

  • keywords set to verified.

+1

12/15/07 06:51:40 changed by bronson

Ticket #10406 is very similar to this one but for ActionMailer::TestCase.

12/16/07 23:38:04 changed by david

  • owner changed from core to michael@koziarski.com.

12/19/07 02:46:18 changed by packagethief

Note: the recent changes to the method_added hook in [8392] prevent setup from working in ActionController::TestCase subclasses at all. This patch, because it aliases setup, fixes the problem.

12/28/07 05:21:33 changed by bitsweat

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

(In [8497]) Ensure that test case setup is run even if overridden. Closes #10382.

12/28/07 05:27:14 changed by bitsweat

(In [8498]) Merge r8497 from trunk: ensure that test case setup is run even if overridden. References #10382.

01/03/08 03:04:10 changed by josh

Umm, we may want to reopen this or start a new ticket because the "method_added" trick doesn't stack with setup_with_fixtures. So, the setup will now fix the controller issue, but we broke fixtures. DUH!

The simple thing todo would be to just add setup_with_fixtures to the top of setup_with_controller. However, I'm still exploring a nice way for them to stack on to each other.

01/03/08 05:26:46 changed by nzkoz

I have to admit I kinda preferred making you call super. But I can see that the community at large doesn't like it.

The best bet is to create a simple parallel method 'setup_rails_framework' or something, and have that get overridden in child classes and monkeypatched by fixtures. That way there's only ever one method to make sure gets called.

Feel like trying that out in another patch / ticket?

01/03/08 06:19:45 changed by josh

05/05/08 11:50:39 changed by aotianlong

+1