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

Ticket #10536 (closed defect: duplicate)

Opened 7 months ago

Last modified 7 months ago

[PATCH] setup method not being called in ActionController::TestCase

Reported by: noelrap Assigned to: core
Priority: normal Milestone: 2.0.3
Component: ActionPack Version: edge
Severity: normal Keywords:
Cc:

Description

Using Rails revision 8430, a number of my functional tests that are subclasses of ActionController::TestCase appear to not be working. In particular, the setup method of the test itself is not being called

class MyControllerTest < ActionController::TestCase
  tests MyController

  def setup
    super
    @user = users(:aaron)
  end

  def test_user
    p @user
  end
end

prints "nil". It does appear that the setup method in ActionController::TestCase is being called.

Older functional tests that subclass from Test::Unit::TestCase are not affected, however helper tests that mock controllers do seem to have the same problem.

Attachments

call_setup_method_in_subclassed_test_case.patch (2.7 kB) - added by kasatani on 12/18/07 10:42:50.
A patch which makes setup methods in subclassed test cases called.

Change History

12/18/07 01:11:02 changed by mczepiel

Actually, seeing the same issue with a test subclassed from Test::Unit::TestCase

12/18/07 10:42:50 changed by kasatani

  • attachment call_setup_method_in_subclassed_test_case.patch added.

A patch which makes setup methods in subclassed test cases called.

12/18/07 10:43:44 changed by kasatani

I've attached a patch (including test case) which fixes the problem. It seems to be a regression caused by a patch in #10379.

12/18/07 18:03:26 changed by mcornick

+1

12/18/07 18:20:11 changed by mcornick

  • summary changed from setup method not being called in ActionController::TestCase to [PATCH] setup method not being called in ActionController::TestCase.

12/19/07 01:13:00 changed by josh

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

12/19/07 01:58:15 changed by kasatani

  • status changed from closed to reopened.
  • resolution deleted.

This isn't a duplicate of #10382. While the patch in #10382 makes you sure that the setup method of ActionController::TestCase is always called even if you don't call "super", this problem shows that the overridden setup method is never called. The example is shown in the patch as SubclassedTestCase class.

12/19/07 02:08:31 changed by kasatani

I meant "overriding" setup method is never called, rather than "overridden" - If you subclass a test case that already has setup method and override it, the setup method in superclass is always called, whereas the one in subclass is never called.

12/19/07 22:30:26 changed by mcornick

  • status changed from reopened to closed.
  • resolution set to duplicate.

duplicated by #10568, fixed in [8442]

12/20/07 09:31:51 changed by joergd

+ 1

12/20/07 10:12:08 changed by kasatani

Since this issue has been fixed by reverting the original patch in #10379, this patch has been moved there merged with the original patch. Please vote there :)