From 16090717f2ea85e9e40ff59498f40c262de684e4 Mon Sep 17 00:00:00 2001 From: filipe Date: Wed, 15 Aug 2007 03:03:32 +0000 Subject: [PATCH] Make CGI Wrapper work with CGI::Session (closes: #8386) git-svn-id: svn+ssh://rubyforge.org/var/svn/mongrel/trunk@555 19e92222-5c0b-0410-8929-a290d50e31e9 --- lib/mongrel/cgi.rb | 6 +++--- test/test_cgi_wrapper.rb | 28 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 test/test_cgi_wrapper.rb diff --git a/lib/mongrel/cgi.rb b/lib/mongrel/cgi.rb index fa5c9c4e..4173bde9 100644 --- a/lib/mongrel/cgi.rb +++ b/lib/mongrel/cgi.rb @@ -109,10 +109,10 @@ module Mongrel end @head.delete('cookie') - - # @output_cookies seems to never be used, but we'll process it just in case - @output_cookies.each {|c| to['Set-Cookie'] = c.to_s } if @output_cookies end + + # @output_cookies seems to never be used, but we'll process it just in case + @output_cookies.each {|c| to['Set-Cookie'] = c.to_s } if @output_cookies end # The dumb thing is people can call header or this or both and in any order. diff --git a/test/test_cgi_wrapper.rb b/test/test_cgi_wrapper.rb new file mode 100644 index 00000000..0db0655c --- /dev/null +++ b/test/test_cgi_wrapper.rb @@ -0,0 +1,28 @@ +require 'test/unit' +require 'rubygems' +require 'mongrel' +require 'cgi/session' + +class MockHttpRequest + attr_reader :body + + def params + return { 'REQUEST_METHOD' => 'GET'} + end +end + +class CGIWrapperTest < Test::Unit::TestCase + + def test_set_cookies_output_cookies + request = MockHttpRequest.new + response = nil # not needed for this test + output_headers = {} + + cgi = Mongrel::CGIWrapper.new(request, response) + session = CGI::Session.new(cgi, 'database_manager' => CGI::Session::MemoryStore) + cgi.send_cookies(output_headers) + + assert(output_headers.has_key?("Set-Cookie")) + assert_equal("_session_id="+session.session_id+"; path=", output_headers["Set-Cookie"]) + end +end \ No newline at end of file