次の手順でキュウリのシナリオがあります。
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
3 番目のリクエストでわかるように、セッション オブジェクトは空です (最後のアクションで適切に設定されていることはわかっていますが)。リダイレクト後のリクエスト間でセッション データが保持されていないようですが、その理由がわかりません (何時間も費やしました!)。何か案は?