栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何在Rails功能测试中发送原始发布数据?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何在Rails功能测试中发送原始发布数据?

我今天遇到了同一问题,找到了解决方案。

在您

test_helper.rb
的内部定义以下方法
ActiveSupport::TestCase

def raw_post(action, params, body)  @request.env['RAW_POST_DATA'] = body  response = post(action, params)  @request.env.delete('RAW_POST_DATA')  responseend

在功能测试中,与

post
方法一样使用它,但将原始文章正文作为第三个参数传递。

class LegacyOrderUpdateControllerTest < ActionController::TestCase  test "sending json" do    raw_post :index, {}, {:foo => "bar", :bool => true}.to_json  endend

我在Rails 2.3.4上使用读取原始文章正文时对此进行了测试

request.raw_post

代替

request.body.read

如果您查看源代码,您会发现它

raw_post
只是在env哈希中加上了对它
request.body.read
的检查。
RAW_POST_DATA``request



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/485518.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号