Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActionController::InvalidCrossOriginRequest in Controller Test

When running legacy controller tests like this one:

    get :edit, id: object.id, format: :js 

My tests began failing in Rails 4.1 with the following error:

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. 
like image 893
Tom Rossi Avatar asked Jul 23 '14 19:07

Tom Rossi


1 Answers

For Rails 5+

get :edit, params: { id: object.id }, xhr: true 
like image 193
John Pollard Avatar answered Sep 18 '22 15:09

John Pollard