开发者

Raw POST from Ruby on Rails

开发者 https://www.devze.com 2022-12-08 03:08 出处:网络
I\'m trying to do a raw POST to an internal page from a unit test, and for some reason I\'m getting the following error:

I'm trying to do a raw POST to an internal page from a unit test, and for some reason I'm getting the following error:

NoMethodError: undefined method `symbolize_keys' for #<String:0x258a910>
    unit/call_route_attempt_test.rb:10:in `test_response_from_call_info'

My code looks like this:

post :call_info, '<?xml version="1.0" encoding="UTF-8"?><request-call-info>...SOME XML HERE...</request-call-info>'

That should be fine according to the API docs. The only format I can get to work is if I send it as parameters like so:

post :call_info, :post => {:a_var => '<?xml version="1.0" encoding="UTF-8"?><request-call-info>...SOME XML HERE...</request-call-info>'}

I have a feeling I need to require some part of the library that for some reason isn't working here.

Edit

As user Sarah Mei points out, I'm calling the wrong post method. I think it has to do with my cla开发者_StackOverflowss inheritance, which I'm not sure I can change given the circumstances of me running a test. The class definition is as follows:

class anApiControllerTest < ActionController::TestCase

The method I'm trying to implement is the post (ActiveResource::Connection) method listed on the Rails API docs. I'm really new to this, quite lost and on a deadline. Any help is greatly appreciated. Thanks!


It depends on which post method you're calling. There's one in ActionController::Integration::Session, one in ActionController::TestProcess, one in ActiveResource::Connection...etc. Most of them take a params hash as the second parameter, so if the second call works, you're probably not calling the post you think you're calling.

0

精彩评论

暂无评论...
验证码 换一张
取 消