# Posting within an integration test with RoR 2

**URL:** <https://www.ruby-forum.com/t/posting-within-an-integration-test-with-ror-2/132916>\
**Category:** Rails\
**Created:** [March 25, 2008, 7:47pm UTC](https://www.ruby-forum.com/t/posting-within-an-integration-test-with-ror-2/132916 "2008-03-25T19:47:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![iberci](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/a3d4f5/32.png) [@iberci](https://www.ruby-forum.com/u/iberci)\
**Post date:** [March 25, 2008, 7:47pm UTC](https://www.ruby-forum.com/t/posting-within-an-integration-test-with-ror-2/132916/1 "2008-03-25T19:47:56Z")

</div>

When I am posting from within an Integration test, at  
/usr/lib/ruby/gems/1.8/actionpack-2.0.2/lib/action\_controller:parse\_formatted\_request\_parameters,  
I get the an exception (listed below) at line 374:

`
   362 def parse_formatted_request_parameters
   363 return {} if content_length.zero?
   364
   365 content_type, boundary =
self.class.extract_multipart_boundary(content_type_with_parameter
s)
   366
   367 # Don't parse params for unknown requests.
   368 return {} if content_type.blank?
   369
   370 mime_type = Mime::Type.lookup(content_type)
   371 strategy =
ActionController::Base.param_parsers[mime_type]
   372
   373 # Only multipart form parsing expects a stream.
=> 374 body = (strategy && strategy != :multipart_form) ?
raw_post : self.body
   375
   376 case strategy
   377 when Proc
   378 strategy.call(body)
   379 when :url_encoded_form
   380 self.class.clean_up_ajax_request_body! body
   381 self.class.parse_query_parameters(body)
   382 when :multipart_form
   383 self.class.parse_multipart_form_parameters(body,
boundary, content_length, env)
   384 when :xml_simple, :xml_node
   385 body.blank? ? {} :
Hash.from_xml(body).with_indifferent_access
   386 when :yaml
   387 YAML.load(body)
   388 else
   389 {}
   390 end
   391 rescue Exception => e # YAML, XML or Ruby code block
errors
   392 raise
   393 { "body" => body,
   394 "content_type" => content_type_with_parameters,
   395 "content_length" => content_length,
   396 "exception" => "#{e.message} (#{e.class})",
   397 "backtrace" => e.backtrace }
   398 end
`

where the raw\_post() is in the ternary is defined as:  
`
277 def raw_post
278 unless env.include? ‘RAW_POST_DATA’
=> 279 env[‘RAW_POST_DATA’] = body.read(content_length)
280 body.rewind if body.respond_to?(:rewind)
281 end
282 env[‘RAW_POST_DATA’]
283 end
`

Line 279 raises with an ArgumentError: 1 for 0 where the partial trace  
is:

“/usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/request.rb:279:in  
`read'", "/usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/request.rb:279:in`raw\_post’”,  
“/usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/request.rb:374:in  
`parse_formatted_request_parameters'", "/usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/cgi_process.rb:78:in`request\_parameters’”,  
“/usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/request.rb:287:in  
`parameters’”,

the body method is actually defined in  
/usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/cgi\_process.rb:

`
   65 def body
   66 if raw_post = env['RAW_POST_DATA']
   67 StringIO.new(raw_post)
   68 else
=> 69 @cgi.stdinput
   70 end
   71 end
`

where @cgi is an ActionController::Integration::Session::StubCGI and the  
@cgi.stdinput reports to being a StringIO

but when this StringIO method is used to perform a read, I get the error  
listed above…

Is anyone familiar with posting within integration testing and how I  
could possibly skirt around this issue?

Thanks for any tips on this issue…

ilan

---

<div class="post-metadata">

**Author:** ![iberci](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/a3d4f5/32.png) [@iberci](https://www.ruby-forum.com/u/iberci)\
**Post date:** [March 25, 2008, 9:39pm UTC](https://www.ruby-forum.com/t/posting-within-an-integration-test-with-ror-2/132916/2 "2008-03-25T21:39:20Z")

</div>

as a follow up, I found that I had monkey patch conflicts with  
redhillonrails\_core 2.0 which I use for foreign key constraints on my  
db…

phew…
