让 Devise 和 Declarative 在 RSpec 测试中发挥出色非常困难。
https://github.com/stffn/declarative_authorization/issues/95
在功能测试中补充会话变量后出现 stringify_keys 错误
这些都解决了我的问题,但都没有适合我的解决方案。
# practices_controller_spec.rb
it "assigns a new practice as @practice as owner" do
get_action(:new, @owner)
assigns(:practice).should be_a_new(Practice)
sign_out @owner
end
def get_action(action,user,*id)
sign_in user
get_with user, action, {:id => id}, session
end
# Spec test yields
Failure/Error: get_with user, action, {:id => id}, session
NoMethodError:
private method `stringify_keys' called for #<ActionController::TestSession:0x00000100d8a170>
Session looks like this: {"warden.user.user.key"=>["User", [1840], "$2a$04$2Rq4bHGp.tlIgKHE4PlRle"]}
有什么建议可以解决这个错误吗?
任何帮助将不胜感激。谢谢!
更新
我通过这样做使它工作:
def get_action(action,user,*id)
sign_in user
hashy = session['warden.user.user.key'][2]
get_with user, action, {:id => id}, {"warden.user.user.key"=>["User", [user.id],hashy]}, nil
结尾