运行像这样的传统控制器测试时:
get :edit, id: object.id, format: :js
我的测试在Rails 4.1中开始失败,出现以下错误:
ActionController::InvalidCrossOriginRequest: Security warning: an embedded <script> tag on another site requested protected JavaScript. If you know what you're doing, go ahead and disable forgery protection on this action to permit cross-origin JavaScript embedding.
答案 0 :(得分:38)
旧版本的Rails接受了这个,但解决方案是使用xhr
方法,如下所示:
xhr :get, :edit, id: object.id
答案 1 :(得分:33)
对于Rails 5 +
get :edit, params: { id: object.id }, xhr: true