2014-07-23 26 views
22

Podczas uruchamiania testów kontrolerów starszych jak ten:ActionController :: InvalidCrossOriginRequest w test kontrolera

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

moich testów rozpoczął braku w Rails 4.1 z następującym błędem:

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. 

Odpowiedz

17

Dla szyn 5+

get :edit, params: { id: object.id }, xhr: true 
35

Starsze wersje Rails zaakceptowanych to, ale rozwiązaniem było użycie metody xhr w następujący sposób:

xhr :get, :edit, id: object.id 
+3

Ta składnia została zmieniona na 'get edit_url (object), xhr: true' w Rails 5. –