XML POST Datamapper 成功,但是 GET 请求 returns []

XML POST successful to Datamapper, but GET request returns []

我正在尝试 POST XML 并将其存储在数据映射器中。 POST 格式响应在 Postman 中显示并看起来有效,但是当我发出 GET 请求时,返回 []。

这是我正在使用的示例XML

<?xml version="1.0" encoding="UTF-8"?>
<testsuite name="Test"
           tests="4"
           failures="0"
           errors="0"
           skipped="4"
           time="0.002">
  <properties />

            <testcase name=“name” time="0.0" classname="classname">
          <skipped />
    </testcase>
            <testcase name="name" time="0.0" classname="classname">
          <skipped />
    </testcase>
            <testcase name="name" time="0.0" classname="classname">
          <skipped />
    </testcase>
            <testcase name="name" time="0.0" classname="classname">
          <skipped />
    </testcase>


</testsuite>

样本 format_response 来自 POST

{"testsuite":null,"testcase":[{"skipped":null,"name":"name","time":"0.0","classname":"classname"},{"skipped":null,"name":"name","time":"0.0","classname":"classname"},{"skipped":null,"name":"name","time":"0.0","classname":"classname"},{"skipped":null,"name":"name","time":"0.0","classname":"classname"}],"name":"Test","tests":"4","failures":"0","time":"0.002","classname":"classname"}

这是我的模型

class SuiteConfiguration
  include DataMapper::Resource

  property :testsuite, Serial
  property :testcase, Serial
  property :name, String
  property :tests, String
  property :failures, String
  property :time, String
  property :classname, String
end

我的路线

get '/api/tests' do
  format_response(SuiteConfiguration.all, request.accept)
end

post '/api/tests' do
  body = Crack::XML.parse request.body.read

  config = SuiteConfiguration.create(
      testsuite: body['testsuite'][0],
      testcase: body['testsuite']['testcase'],
      classname: body['testsuite']['testcase'][0]['classname'],
      name: body['testsuite']['name'],
      tests: body['testsuite']['tests'],
      failures: body['testsuite']['failures'],
      time: body['testsuite']['time'],
  )
  status 201
  format_response(config, request.accept)
end

在我的 POST 响应中看到它没有正确打印后,我将我的测试套件和测试用例属性更改为对象,尽管测试套件仍然显示为空:

class SuiteConfiguration
  include DataMapper::Resource

  property :id, Serial
  property :testsuite, Object
  property :testcase, Object
  property :name, String
  property :tests, String
  property :failures, String
  property :time, String
  property :classname, String
end

并更改了我的 post 以获取测试用例中的每个值

    post '/api/tests' do
  body = Crack::XML.parse request.body.read

  config = SuiteConfiguration.create(
      testcase: body['testsuite']['testcase'].each do |value|
        value          
      end,
      name: body['testsuite']['name'],
      tests: body['testsuite']['tests'],
      failures: body['testsuite']['failures'],
      time: body['testsuite']['time'],
  )
  status 201
  format_response(config, request.accept)
end

现在我从 datamapper 收到一个 GET 请求,其中包含我需要的信息。