Functional testing and session[:session_id]

Hey Guys,

Does Rails set the session[:session_id] field in functional testing?
I’ve been getting an empty string… which is causing the url_for
function call in my view to blow up. It would be really nice to avoid
the following ugly workaround…

<%= if session.session_id != ‘’
link_to ‘Sign Out’, session_url(:id => session.session_id), :method =>
:delete end %>

Sonny.

You can use @request.session[:session_id] = user.id in the setup
method to artificially login in users for the functional tests.

On Jul 13, 2:41 pm, Sonny C. [email protected]

danlunde wrote:

You can use @request.session[:session_id] = user.id in the setup
method to artificially login in users for the functional tests.

On Jul 13, 2:41 pm, Sonny C. [email protected]

I’ve tried that but and gotten the following error message:

ActionView::TemplateError: session_url failed to generate from
{:controller=>“sessions”, :id=>“”, :action=>“show”}, expected:
{:controller=>“sessions”, :action=>“show”}, diff: {:id=>“”}
On line #21 of app/views/layouts/application.rhtml

18: Signed in as <%= link_to user.name, user_url(:id => user)%>
19:

20: <%= link_to ‘Settings’, edit_user_url(:id => current_user)%>
21: <%= link_to ‘Sign Out’, session_url(:id => session.session_id),
:method => :delete %>

Maybe line 21 should be

session_url(:id => session[:session_id], :method => :delete))
or
session_url(:id => current_user, :method => :delete)

On Jul 13, 5:53 pm, Sonny C. [email protected]

danlunde wrote:

Maybe line 21 should be

session_url(:id => session[:session_id], :method => :delete))
or
session_url(:id => current_user, :method => :delete)

On Jul 13, 5:53 pm, Sonny C. [email protected]

Thanks for the suggestions, but alas,

  1. session[:session_id] is nil in the rendered view

  2. :id=>current_user will work… but if someone was malicious they
    could spam my site with session_url(:id => random_number, :method =>
    :delete) which would result in my users being logged out
    unexpectedly…

Sonny.