补充功能测试中的会话变量后的stringify_keys错误 [英] stringify_keys error after supplementing session variables in functional tests

查看:100
本文介绍了补充功能测试中的会话变量后的stringify_keys错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从3.0.10升级到Rails 3.1.0,我正在使用Devise进行身份验证。

I'm in the process of upgrading to Rails 3.1.0 from 3.0.10, and I'm using Devise for authentication.

我有一些需要我设置单个会话变量的功能测试。东西沿着以下行:

I have a number of functional tests that require me to set a single session variable. Stuff along the lines of:

test "new clears current_lesson_id from session" do
  get :new, nil, {'current_lesson_id' => '234234'}
  assert_response :success
  assert_nil session[:current_lesson_id]
end

这是失败的,因为我的会话信息破坏了设计认证会话数据,所以我以前的解决方案是与默认会话合并:

This was failing as my session info was clobbering the devise authentication session data, so my previous solution was to merge with the default session:

test "new clears current_lesson_id from session" do
  get :new, nil, authenticated_sesion_with({'current_lesson_id' => '234234'})
  assert_response :success
  assert_nil session[:current_lesson_id]
end

def authenticated_session_with(hash)
  session.merge(hash)
end

所有这一切对于rails 3.0.10(带有监听器1.0.4和devise 1.4.2)都不错,但不再使用rails 3.1.0和监狱长1.0.5,设计1.4.4)。现在我收到以下错误:

All of this worked fine with rails 3.0.10 (with warden 1.0.4 and devise 1.4.2), but no longer with rails 3.1.0 (and warden 1.0.5, devise 1.4.4). Now I'm getting the following error:

NoMethodError: private method `stringify_keys' called for <ActionController::TestSession:0x000001060db590>

我收集的是因为'session'对象是ActionController :: TestSession的一个实例, rails 3.1.0有一堆实例变量不能也不应该被'stringified'。

I gather this is because the 'session' object is an instance of ActionController::TestSession, and in rails 3.1.0 there are a bunch of instance variables that can't and shouldn't be 'stringified'.

我应该如何正确访问设计用户信息动态),所以我可以添加'current_lesson_id'等。

How should I properly access the devise user information (preferably dynamically) so I can add 'current_lesson_id', etc.?

多谢,

推荐答案

我想你最好做:

def valid_session
    my_session_values = {:some_key => :some_value}
    session.to_hash.merge my_session_values
end

这篇关于补充功能测试中的会话变量后的stringify_keys错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆