我无法让这个工作,所以任何帮助将不胜感激!基本上,request.body包含Web服务的有效XML,如下所示:
<somedata>
<name>Test Name 1</name>
<description>Some data for Unit testing</description>
</somedata>
Run Code Online (Sandbox Code Playgroud)
...但该服务返回空XML.请注意,返回id字段表明它实际上确实命中了数据库,但名称和描述字段为nil:
<somedata>
<id type='integer'>1</id>
<name nil='true'></name>
<description nil='true'></description>
</somedata>
Run Code Online (Sandbox Code Playgroud)
我已经使用Poster手动测试了RESTFUL服务,它运行正常.
这是代码:
url = URI.parse('http://localhost:3000/someservice/')
request = Net::HTTP::Post.new(url.path)
request.body = "<?xml version='1.0' encoding='UTF-8'?><somedata><name>Test Name 1</name><description>Some data for Unit testing</description></somedata>"
response = Net::HTTP.start(url.host, url.port) {|http| http.request(request)}
#Note this test PASSES!
assert_equal '201 Created', response.get_fields('Status')[0]
Run Code Online (Sandbox Code Playgroud)
有没有人有任何线索为什么XML帖子中的数据不会持久存在?
我在Ruby中开发了一个简单的库,需要在几个Rails应用程序中使用它(其中一些还没有构建).在需要时,将这个Ruby库轻松添加到多个Rails应用程序的最佳方法是什么?我们的团队正在运行Ubuntu,我们的存储库是Mercurial.
我应该用...
任何指针将非常感谢!