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

Ticket #6353 (closed defect: fixed)

Opened 2 years ago

Last modified 1 year ago

[PATCH] Undefined method recycle! in integration test with put or delete

Reported by: jgarber Assigned to: David
Priority: normal Milestone: 1.2
Component: ActionPack Version: 1.2.3
Severity: major Keywords: integration rest recycle!
Cc: bitsweat, caboose

Description

In a simple integration test with trunk, I get:

>> get 'books/1'
=> 200
>> put 'books/1'
NoMethodError: undefined method `recycle!' for #<ActionController::CgiRequest:0x2cef98c>
        from /Users/jasongarber/Documents/form_test_helper/config/../vendor/rails/actionpack/lib/action_controller/cgi_process.rb:127:in `method_missing'
        from /Users/jasongarber/Documents/form_test_helper/config/../vendor/rails/actionpack/lib/action_controller/test_process.rb:357:in `process'
        from /Users/jasongarber/Documents/form_test_helper/config/../vendor/rails/actionpack/lib/action_controller/test_process.rb:340:in `put'
        from (irb):1:in `breakpoint'
        from /Users/jasongarber/Documents/form_test_helper/config/../vendor/rails/railties/lib/breakpoint.rb:536:in `breakpoint'
        from /Users/jasongarber/Documents/form_test_helper/config/../vendor/rails/railties/lib/breakpoint.rb:536:in `breakpoint'
        from test/integration/integration_test.rb:10:in `test_truth'
        from /usr/local/lib/ruby/1.8/test/unit/testcase.rb:70:in `run'
        from /Users/jasongarber/Documents/form_test_helper/config/../vendor/rails/actionpack/lib/action_controller/integration.rb:453:in `run'
        from /usr/local/lib/ruby/1.8/test/unit/testsuite.rb:32:in `run'
        from /usr/local/lib/ruby/1.8/test/unit/testsuite.rb:31:in `run'
        from /usr/local/lib/ruby/1.8/test/unit/testsuite.rb:32:in `run'
        from /usr/local/lib/ruby/1.8/test/unit/testsuite.rb:31:in `run'
        from /usr/local/lib/ruby/1.8/test/unit/ui/testrunnermediator.rb:44:in `run_suite'
        from /usr/local/lib/ruby/1.8/test/unit/ui/console/testrunner.rb:65:in `start_mediator'
        from /usr/local/lib/ruby/1.8/test/unit/ui/console/testrunner.rb:39:in `start'
        from /usr/local/lib/ruby/1.8/test/unit/ui/testrunnerutilities.rb:27:in `run'
        from /usr/local/lib/ruby/1.8/test/unit/autorunner.rb:200:in `run'
        from /usr/local/lib/ruby/1.8/test/unit/autorunner.rb:13:in `run'
        from /usr/local/lib/ruby/1.8/test/unit.rb:285

Attachments

define_put_and_delete.diff (0.6 kB) - added by caboose on 02/20/07 22:57:55.
..and HEAd
define_http_verbs_TESTED.diff (2.2 kB) - added by caboose on 02/22/07 07:26:42.
Some basic tests for integration meta-testing.
6353.1-2-stable.patch (2.4 kB) - added by mpalmer on 08/15/07 01:44:59.
Previous patch, rebased against r7277 (1-2-stable)

Change History

(in reply to: ↑ description ; follow-up: ↓ 2 ) 10/06/06 03:03:44 changed by jgarber

It works when you open_session and then put/delete with that session, but not in the raw integration test. Shouldn't it?

(in reply to: ↑ 1 ) 02/20/07 22:09:45 changed by caboose

Replying to jgarber:

It works when you open_session and then put/delete with that session, but not in the raw integration test. Shouldn't it?

I get this in integration tests too. others don't. Investigating..

02/20/07 22:37:09 changed by caboose

how an integration test runs:

1. action_controller/integration.rb:453 'run'

doesn't do anything. as the comment says

# Work around test/unit's requirement that every subclass of TestCase have # at least one test method. Note that this implementation extends to all # subclasses, as well, so subclasses of IntegrationTest may also exist # without any test methods.

2. your original_test.rb: 'test_whatever'

3. if your installation is broken, you'll see

   test_process.rb:353:in `put'
   test_process.rb:370:in `process'
   cgi_process.rb:139:in `method_missing'

if your installation works, then you'll see

testcase.rb:72 '__send__'

which wraps around your test method and rescues all the types of errors and turns them into failures as necessary.

in the case of success, the test continues on to ..

3. action_controller/integration.rb:547 'method_missing'

# Delegate unhandled messages to the current session instance.

in this case, the message is 'put' or 'get'

if there's an integration session, it doesn't reset all the variables like request.host and routing.

if there is a session, it passes on the session variables to the request.

4. action_controller/integration.rb:162 'put' so, it seems the bug is in test_process.rb. Indeed, if I comment out lines 348..onwards which start

    def self.included(base)
      # execute the request simulating a specific http method and set/volley the response
      %w( get post put delete head ).each do |method|
        base.class_eval <<-EOV, __FILE__, __LINE__
          def #{method}(action, parameters = nil, session = nil, flash = nil)

the issue is, it tries to overwrite put, get, etc, with the process action in test_process. however, in integration.rb, those methods already exist, so somewhere, the integration test's put and delete methods aren't being used, rather, test_process' are.

02/20/07 22:52:18 changed by caboose

  • summary changed from Undefined method recycle! in integration test with put or delete to [PATCH] Undefined method recycle! in integration test with put or delete.

i don't know how this can be tested, since it fails for different people, and in addition, the current actionpack edge fails a bunch of other test. however, here's the patch.

is there a reason put and delete aren't defined in this place?

02/20/07 22:57:55 changed by caboose

  • attachment define_put_and_delete.diff added.

..and HEAd

02/21/07 09:24:36 changed by bitsweat

  • cc set to bitsweat.
  • status changed from new to closed.
  • resolution set to untested.

02/22/07 07:26:42 changed by caboose

  • attachment define_http_verbs_TESTED.diff added.

Some basic tests for integration meta-testing.

02/22/07 07:49:54 changed by caboose

  • cc changed from bitsweat to bitsweat, caboose.
  • status changed from closed to reopened.
  • resolution deleted.

now with 200% more tests!

02/22/07 09:29:07 changed by bitsweat

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

08/15/07 01:43:55 changed by mpalmer

  • status changed from closed to reopened.
  • version changed from edge to 1.2.3.
  • resolution deleted.

As per this thread on rails-core, I'm reopening this for application against 1-2-stable.

08/15/07 01:44:59 changed by mpalmer

  • attachment 6353.1-2-stable.patch added.

Previous patch, rebased against r7277 (1-2-stable)

08/15/07 01:46:33 changed by mpalmer

Just to be clear, I've checked this patch (that the patch applies cleanly, that the tests highlight a problem, and that the live code fixes the problem).

08/15/07 03:57:21 changed by nzkoz

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

(In [7319]) Integration tests: introduce methods for other HTTP methods. Closes #6353. Merges [6203]

(follow-up: ↓ 12 ) 08/21/07 20:50:45 changed by jemminger

i've applied this patch to rails 1.2.3 on osx 10.4.10, and while i no longer get the undefined method error, if i try to use method put in an integration test, i get a routing error:

ActionController::RoutingError (no route found to match "/medias/12;edit" with {:method=>:put}):
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/routing.rb:1292:in `recognize_path'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/routing.rb:1282:in `recognize'
    /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:40:in `dispatch'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/integration.rb:257:in `process'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/integration.rb:157:in `post'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/integration.rb:498:in `send'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/integration.rb:498:in `post'
    ./test/integration/user_stories_test.rb:61:in `test_can_complete_profile'
    /usr/local/lib/ruby/gems/1.8/gems/mocha-0.5.2/lib/mocha/test_case_adapter.rb:19:in `__send__'
    /usr/local/lib/ruby/gems/1.8/gems/mocha-0.5.2/lib/mocha/test_case_adapter.rb:19:in `run'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/integration.rb:453:in `run'
    /usr/local/lib/ruby/gems/1.8/gems/test-spec-0.3.0/lib/test/spec.rb:442:in `run'
    /usr/local/lib/ruby/gems/1.8/gems/test-spec-0.3.0/lib/test/spec.rb:441:in `each'
    /usr/local/lib/ruby/gems/1.8/gems/test-spec-0.3.0/lib/test/spec.rb:441:in `run'
    /usr/local/lib/ruby/gems/1.8/gems/test-spec-0.3.0/lib/test/spec.rb:442:in `run'
    /usr/local/lib/ruby/gems/1.8/gems/test-spec-0.3.0/lib/test/spec.rb:441:in `each'
    /usr/local/lib/ruby/gems/1.8/gems/test-spec-0.3.0/lib/test/spec.rb:441:in `run'
    /usr/local/lib/ruby/1.8/test/unit/ui/testrunnermediator.rb:46:in `run_suite'
    /Users/jemminger/Documents/aptana-workspace/.metadata/.plugins/org.rubypeople.rdt.testunit/RemoteTestRunner.rb:107:in `start_mediator'
    /Users/jemminger/Documents/aptana-workspace/.metadata/.plugins/org.rubypeople.rdt.testunit/RemoteTestRunner.rb:52:in `start'
    /Users/jemminger/Documents/aptana-workspace/.metadata/.plugins/org.rubypeople.rdt.testunit/RemoteTestRunner.rb:298

my routes.rb does define 'map.resources :medias'

the call in the integration test is:

 put edit_media_url(current_user.medias.first),
  :media => {:title => 'blah', :tags => 'foo bar'}

the put method works as expected in functional tests.

(in reply to: ↑ 11 ) 08/22/07 13:55:04 changed by jemminger

Replying to jemminger:

i've applied this patch to rails 1.2.3 on osx 10.4.10, and while i no longer get the undefined method error, if i try to use method put in an integration test, i get a routing error:

actually this is working just fine... the routing error is my own fault. i should be putting to /medias/x, not /medias/x;edit