Setting Session Data the Old-School Way

Rails provides an easy way to send session data in functional tests when accessing an action (the 3rd parameter is session data):

  get :index, {}, {:user_id => 1}

As you add to your functional test suite, this becomes quite tedious and doesn't play well with tools like Shoulda. Here's where doing it the old-school way helps:

context "A GET to :index" do
  context "as a logged-in user" do
    setup do
      @request.session[:user_id] = Factory(:user).id
      get :index
    end

    should_assign_to :messages      
    should_render_template 'index'
  end
end

Thanks to Matt for giving me a hand with this today.