Today I ran into the same problem and found a solution.
In your test_helper.rb, define the following method inside ActiveSupport :: TestCase:
def raw_post(action, params, body) @request.env['RAW_POST_DATA'] = body response = post(action, params) @request.env.delete('RAW_POST_DATA') response end
In your functional test, use it in the same way as the post method, but pass the original message body as the third argument.
class LegacyOrderUpdateControllerTest < ActionController::TestCase test "sending json" do raw_post :index, {}, {:foo => "bar", :bool => true}.to_json end end
I tested this on Rails 2.3.4 while reading the original message body using
request.raw_post
instead
request.body.read
If you look at the source code , you will see that raw_post just wraps request.body.read with the check for this RAW_POST_DATA in an env hash request.
bbrowning Jan 21 '10 at 3:19 2010-01-21 03:19
source share