“Can't verify CSRF token authenticity” when testing emberjs/rails/devise app using qunit

 ̄綄美尐妖づ 提交于 2019-12-12 16:49:46

问题


I have a emberjs/rails application using devise for user authentication. I am building integration tests using qunit. I manually log into the app before I run tests. GET requests can be processed during tests, but POST requests fail. In particular, when making a POST request, I'm getting a "Can't verify CSRF token authenticity" error from devise. When I reload tests, I am logged out of app.

How do I get qunit to play nice with devise?


回答1:


You need to add csrf_meta_tags to the index.html.erb that you are using to run your qunit tests and you also need to include jquery-ujs. Have a look at https://github.com/frodsan/qunit-rails

Alternatively, you can add this to your application_controller:

skip_before_filter :verify_authenticity_token if Rails.env.test?


来源:https://stackoverflow.com/questions/17177218/cant-verify-csrf-token-authenticity-when-testing-emberjs-rails-devise-app-usi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!