I recently submitted http://dev.rubyonrails.org/ticket/11091 which
allows using uploaded files in integration tests.
However, although the actual code seems to work fine, the testcase I
submitted seems to be breaking non-related testcases, due to the way I
tried to set up routing for the test. Duck punching the Routeset
wasn't a good idea.
So now I'm trying to fix that but I'm having problems with the set up.
I can't seem to get my path recognized. Right now I'm trying code
like this:
http://pastie.caboo.se/153714
Stepping through the code with rdebug, shows that the routes are
indeed set up correctly by TestProcess#with_routes at the time I do
the post, using the dump_routes method I added to Object for
debugging purposes, which is in the referenced code.
Stepping through the post shows that they are correct up to the point
where ActionController::Routing::RouteSet#recognize_path is entered at
which point it seems to have been reset back to the way the were
before the with_routes call, although I set a breakpoint in the ensure
block so I'm pretty sure that with_routes isn't doing that. As a
matter of fact, I can't see how it could.
Any advice from those more wizened in the ways of testing the rails
test infrastructure code? I suspect that this might be a problem the
route optimization logic but I haven't been able to pin it down.
I'm making some progress on this but I'm not quite there yet.
Here's the current test
http://pastie.caboo.se/154234
I had to stub Dependencies to prevent reloading the application before
the dispatch which is what was destroying my routing.
The code in the pastie works as long as I run it directly a from
vendor/rails/actionpack/test with ruby
controller/integration_upload_test.rb. But if I run it as part of
rake test either from vendor/rails/actionpack or vendor/rails:
1) It no longer breaks non-related tests - GOOD
2) It fails - BAD
Full output here: Parked at Loopia
1) Error:
test_post_with_upload(SessionUploadTest):
NoMethodError: undefined method `content_type' for nil:NilClass
./test/controller/integration_upload_test.rb:55:in `test_post_with_upload'
./test/../lib/action_controller/test_process.rb:505:in `with_routing'
./test/controller/integration_upload_test.rb:47:in `test_post_with_upload'
./test/abstract_unit.rb:32:in `uses_mocha'
./test/controller/integration_upload_test.rb:45:in `test_post_with_upload'
./test/../lib/../../activesupport/lib/active_support/testing/setup_and_teardown.rb:59:in
`__send__'
./test/../lib/../../activesupport/lib/active_support/testing/setup_and_teardown.rb:59:in
`run'
1811 tests, 8844 assertions, 0 failures, 1 errors
So for some reason @session.request contains the request if I run this
directly, but NOT if I run it as part of the rake task.
I thought I might be able to move the assertion to inside the action
method in the controller, but the test doesn't actually seem to be
running the action method. ???
I'd be happy for any ideas about how to properly meta-test the rails
integration test infrastructure.