集成测试 Authlogic before_filter :require_admin_user 问题
尽管创建了管理员用户会话,但我无法在集成测试中访问需要管理员用户的 URL。我的测试因 302 错误而失败。
class NewsItemsController < ApplicationController
before_filter :require_admin_user, :except => [:show, :index, :feed]
etc...
end
--test/inetgration/admin_stories.rb --
require 'test_helper'
class AdminStoriesTest < ActionController::IntegrationTest
fixtures :all
setup :activate_authlogic
# if user is an admin he can create a new news_item
def test_creating_a_news_item
assert UserSession.create(users(:admin))
get "news_items/new"
assert_response :success
#etc...
end
end
我在 test.log 中有以下内容:
Unable to load roles_user, underlying cause no such file to load -- roles_user
正如您所期望的那样,我的装置文件被命名为 Roles_users.yml - 所以不确定如何解决这个问题......
I'm not able to access urls in my integration test that require an admin user despite creating an admin user session. My test fails on a 302 error.
class NewsItemsController < ApplicationController
before_filter :require_admin_user, :except => [:show, :index, :feed]
etc...
end
--test/inetgration/admin_stories.rb --
require 'test_helper'
class AdminStoriesTest < ActionController::IntegrationTest
fixtures :all
setup :activate_authlogic
# if user is an admin he can create a new news_item
def test_creating_a_news_item
assert UserSession.create(users(:admin))
get "news_items/new"
assert_response :success
#etc...
end
end
I've got the following in the test.log:
Unable to load roles_user, underlying cause no such file to load -- roles_user
My fixtures file is named roles_users.yml as you would expect - so unsure of how to resolve this...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为新操作是重定向到登录屏幕。
发生这种情况是因为您尚未登录。尝试:
或者用户 ID 实际是什么。
第一个哈希是请求哈希,第二个哈希是会话哈希。
I think the new action is redirecting to the login screen.
This happens because you are not logged in. Try:
or what the user id actually is.
The first hash is the request hash, the second is the session hash.
您可能还需要将 Authlogic::TestCase 添加到您的类中。从我的应用程序(rspec,但相同的想法)
您的应用程序是否需要激活用户?如果有,这个用户是吗?
如果那没有帮助的话。也许粘贴一些调试输出,也许检查创建的用户。
You may also need to put include Authlogic::TestCase in your class. From my app (rspec, but same idea)
Does your application require users to be activated? If so, is this user?
If that doesn't help. perhaps paste in some debug output, maybe an inspect of the created User.
我在集成测试中也遇到了 Authlogic 的问题,并进行了以下修复(来自 这篇文章)对我来说是一个成功的解决方法。
替换:
为:
I was also having a problem with Authlogic in Integration tests, and the following fix (from this post) was a successful workaround for me.
Replace:
With: