[英]“Can't verify CSRF token authenticity” when testing emberjs/rails/devise app using qunit
I have a emberjs/rails application using devise for user authentication. 我有一个使用devise进行用户身份验证的emberjs / rails应用程序。 I am building integration tests using qunit.
我正在使用qunit构建集成测试。 I manually log into the app before I run tests.
在运行测试之前,我手动登录了该应用程序。 GET requests can be processed during tests, but POST requests fail.
可以在测试过程中处理GET请求,但POST请求失败。 In particular, when making a POST request, I'm getting a "Can't verify CSRF token authenticity" error from devise.
特别是,在发出POST请求时,我从设计中收到“无法验证CSRF令牌真实性”错误。 When I reload tests, I am logged out of app.
重新加载测试时,我已退出应用程序。
How do I get qunit to play nice with devise? 如何使qunit与devise玩得很好?
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. 您需要将csrf_meta_tags添加到用于运行qunit测试的index.html.erb中,还需要包含jquery-ujs。 Have a look at https://github.com/frodsan/qunit-rails
看看https://github.com/frodsan/qunit-rails
Alternatively, you can add this to your application_controller: 或者,您可以将其添加到application_controller中:
skip_before_filter :verify_authenticity_token if Rails.env.test?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.