我想从minitest向控制器发布一个xml。
它在正常模式下的工作方式如下:
curl -X POST -H“Content-Type:text / xml”-d“@ / Users / boti / Rails / clients / kevin / search_server / db / search.xml”localhost:3000 / search
我试过这样做:
test "search with invalid xml" do
path_to_file = File.join Rails.root.to_s, 'test', 'search_invalid.xml'
xml = File.read( path_to_file )
@request.env['RAW_POST_DATA'] = xml
post "/search/search", xml, {"Content-type" => "text/xml"}
但是我得到了这个例外:
NoMethodError: undefined method `symbolize_keys' for #<String:0x007fbd7d863188>
答案 0 :(得分:1)
我在测试中这样做:
path_to_file = File.join Rails.root.to_s, 'test', 'search_invalid_xml.xml'
xml = File.read( path_to_file )
@request.env['RAW_POST_DATA'] = xml
post :search, nil, {"Content-type" => "text/xml"}
然后在我的控制器中这样:
search_doc = Nokogiri::XML.parse request.raw_post