我有以下步驟黃瓜情景:使用Rails丟失會話/黃瓜/水豚
Given /^I have logged in$/ do
visit root_url
fill_in 'username', with: 'testuser'
fill_in 'password', with: 'testpass'
click_button 'Log In'
end
如果我跑我的情況&尾我的Rails日誌,我可以證實,1)登錄頁面加載, 2)當提交登錄詳細信息時,他們被接受並且所需的用戶信息被正確存儲在Rails的session
對象中,然後3)在302重定向到登錄後頁面(因此403)之後會話數據丟失, :
Started GET "/" for 127.0.0.1 at 2012-04-18 16:09:41 +0100
Processing by HomeController#index as HTML
Rendered home/index.html.erb within layouts/application (4.6ms)
Completed 200 OK in 9ms (Views: 8.3ms)
Started POST "/" for 127.0.0.1 at 2012-04-18 16:09:41 +0100
Processing by HomeController#index as HTML
Parameters: {"utf8"=>"✓", "is_submitted"=>"true", "username"=>"testuser", "password"=>"[FILTERED]", "commit"=>"Log In"}
DEBUG - login success
DEBUG - session: {"UserId"=>"19fd75c8-0e80-4832-94af-6a93ee74bf46", "Username"=>"testuser", "Password"=>"d68579bfdac2321d05f19042d8dbc49b9dd611c8", "Name"=>"Active User", "Active"=>true}
Redirected to http://www.example.com/app
Completed 302 Found in 3ms
Started GET "/app" for 127.0.0.1 at 2012-04-18 16:09:41 +0100
Processing by HomeController#app as HTML
DEBUG - session: {}
Redirected to http://www.example.com/
Completed 403 Forbidden in 1ms
正如你所見在第三個請求中,會話對象是空的(儘管我們知道它在最後一個操作中設置正確)。看起來,會話數據不會在重定向後的請求之間持續存在,但我無法弄清楚爲什麼(我花了數小時!)。有任何想法嗎?
你應該檢查你的會話存儲在哪裏。在Cookie或數據庫中。請參閱session_store.rb文件。 – 2012-04-18 17:46:01
它使用cookie存儲。 (我應該提到登錄/會話的東西在「真正的瀏覽器」中絕對正常)。 – skinnyfit 2012-04-18 19:33:36