问题描述
我有一个emberjs / rails应用程序使用devise进行用户身份验证。我正在使用qunit构建集成测试。我在运行测试之前手动登录到应用程序。 GET请求可以在测试期间处理,但POST请求失败。特别是在发出POST请求时,我从devise得到一个无法验证CSRF令牌真实性错误。当我重新加载测试时,我已经注销了应用程序。
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.
我如何让qunit玩得很好?
How do I get qunit to play nice with devise?
推荐答案
您需要将csrf_meta_tags添加到您用于运行qunit测试的index.html.erb中,并且还需要包含jquery-ujs。看看
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
或者,您可以将其添加到您的application_controller中:
Alternatively, you can add this to your application_controller:
skip_before_filter :verify_authenticity_token if Rails.env.test?
这篇关于“无法验证CSRF令牌真实性”当使用qunit测试emberjs / rails / devise应用程序时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!