0

我想从 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>
4

1 回答 1

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
于 2013-02-25T11:30:00.367 回答