2011-09-08 81 views
1

我正在從3.0.10升級到Rails 3.1.0,我正在使用Devise進行身份驗證。stringify_keys在功能測試中補充會話變量後出錯

我有一些功能測試,需要我設置一個會話變量。沿線的東西:

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 

這是沒有我的會話信息被重挫的色器件認證會話數據,所以我以前的解決方案是使用默認的會議合併:

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(warden 1.0.4和devise 1.4.2)下運行良好,但不再使用rails 3.1.0(和warden 1.0.5,devise 1.4.4)。現在我發現了以下錯誤:

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

我推測,這是因爲「會話」對象的ActionController :: TestSession的實例,並在鐵軌3.1.0有一堆實例變量,可以'不應該'串化'。

我應該如何正確訪問設計用戶信息(最好是動態的),以便我可以添加'current_lesson_id'等。

謝謝了,

+0

'會議[ 'current_lesson_id'] = 234234''得到:new'咄,對不起。 – doublea

回答

0

試試這個修復您的錯誤的Rails 3.1

sign_in user 
    hashy = session['warden.user.user.key'][2] 
    get :action, nil, {"warden.user.user.key"=>["User", [user.id],hashy]}, nil 

爲我工作。似乎不喜歡Rails處理TestSessions的新方式。

0

我覺得您做的更好:

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