RSpec POST 更改 URL
Rails 3,RSpec 2:
在控制器的 rspec 测试中,我使用 post 并传递一些参数:
it "returns a job id" do
post :new, { :a => 'b'}
response.status.should == 200
end
这工作正常,在控制器中 params[:a] 是 'b'
但是,控制器端的 request.url
是 http://localhost/controller?a=b< /a>
我不想有参数URL,因为在真实场景(外部测试)中,URL 是安全签名的一部分。
我的问题是为什么 rspec post 将参数添加到 URL,而不是像浏览器中的 POST(或 CURL)那样表现?
Rails 3, RSpec 2:
In my rspec test for a controller, I'm using post and pass in some parameters:
it "returns a job id" do
post :new, { :a => 'b'}
response.status.should == 200
end
This works fine and in the controller params[:a] is 'b'
However, request.url
on the controller side is http://localhost/controller?a=b
I don't want to have the parameters in the URL since in a real scenario (outside test) the URL is part of a security signature.
My question is why rspec post adds the parameters to the URL instead of behaving the same way as a POST in a browser (or CURL)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我还没有找到这个问题的答案,但这是我如何设法解决这个问题,以便我的单元测试工作:我在运行单元测试时简单地绕过签名检查。这是代码:
I haven't found an answer for this yet, but here is how I managed to solve the problem so my unit tests work: I simple by-pass signature checking when running unit tests. Here is the code:
我知道这有点旧,但我发现你使用 post 来执行 :new 操作很奇怪。通常 :new 显示一个表单,因此您将拥有 'get :new' 并且在创建测试中您将使用 post, 'post :create, params = {blah: blah}'。
检查您的路线以查看您的 :new 操作是发布还是获取。
I know this is a bit old but I find it strange that you're using post for the :new action. Generally :new shows a form, thus you'd have 'get :new' and in the create test you'd use post, 'post :create, params = {blah: blah}'.
Check your routes to see if your :new action is post or get.