【发布时间】:2016-07-06 15:59:53
【问题描述】:
我正在尝试通过 JSON 适配器测试使用活动模型序列化程序 gem(版本 0.10.2)构建的 JSON 端点(Rails 5)。
当我从 http://localhost:3000/api/posts 发出请求时,我会在响应中获得根节点,使其看起来像文档:
{
"posts": [{
"id": 1,
"title": "Awesome Post Tile",
"content": "Post content"
}]
}
但是当我像这样在 Rspec(3.5 版)中提出请求时:
获取'/api/posts'
根节点没有通过,所以响应体如下所示:
[{
"id": 1,
"title": "Awesome Post Tile",
"content": "Post content"
}]
我的适配器正在初始化器中设置:
ActiveModelSerializers.config.adapter = :json
我在这里做错了吗?我真的不太了解这是 AMS 或 Rspec 的问题还是我的设置问题。
【问题讨论】:
标签: rspec rspec-rails active-model-serializers ruby-on-rails-5