使用 rspec 测试自定义设计和/或 Warden 策略
我看到很多导致 devise 和 Warden 定制授权策略的内容,但我具体要使用 rspec 测试这些解决方案。与此问题类似: 筛选能够签名的用户在 Devise 中
我可以做什么来测试这种实现。 Rails 3.1.1、Devise(最新)等
I see plenty that lead to custom authorization strategies for devise and warden, but what I'm sepcifically after is testing these solutions with rspec. Similar to this question: Filtering users who are able to sign in with Devise
What can I do to test this sort of implementation. Rails 3.1.1, Devise (most current), etc.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于那些将来可能这样做的人,这是我的解决方案:
这个类通过 Devise 设置新的身份验证策略(并且它也可以与 Warden 一起使用,只需进行一些小的更改)。
上一课位于我的 lib/.../strategies 目录中。我还配置了 lib,以便通过 Rails 配置自动加载。
从 rspec 方面来看,在创建上述类之后,我写了一些存根/模拟。这是一个可以帮助您入门的基本 rspec 文件。
这并不包含所有内容,但我认为它应该让我们在使用 Warden 或 Devise 添加策略时拥有良好的开端。实际上,我必须实施我认为可行的方法,然后进行正确的测试以在事后证明它。现在我们也许可以反过来做。
For those that may do this in the future, here is my solution:
This is the class that sets a new strategy for authentication through Devise (and it could also be used with Warden with a few small changes).
The previous class is in my lib/.../strategies directory. I also have lib configured for auto-loading through the rails configuration.
From the rspec side, after I created the above class I write out a few stubs/mocks. Here is a basic rspec file to get you started.
This isn't all inclusive, but I feel it should get us a good head start when adding strategies with Warden or Devise. I actually had to implement what I thought would work and then right tests to prove it after the fact. Now we can do it the other way around perhaps.