From a6fff94baf0ca5d436cbc5c0fa81f690c8024ff5 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Thu, 30 Apr 2009 19:23:50 -0500 Subject: Move TestRequest cookies accessor into AD TestRequest --- .../lib/action_dispatch/testing/test_request.rb | 24 +++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'actionpack/lib/action_dispatch/testing/test_request.rb') diff --git a/actionpack/lib/action_dispatch/testing/test_request.rb b/actionpack/lib/action_dispatch/testing/test_request.rb index 3d20b466d3..bd6c26b69b 100644 --- a/actionpack/lib/action_dispatch/testing/test_request.rb +++ b/actionpack/lib/action_dispatch/testing/test_request.rb @@ -1,17 +1,24 @@ module ActionDispatch class TestRequest < Request + DEFAULT_ENV = Rack::MockRequest.env_for('/') + def self.new(env = {}) super end def initialize(env = {}) - super(Rack::MockRequest.env_for('/').merge(env)) + super(DEFAULT_ENV.merge(env)) self.host = 'test.host' self.remote_addr = '0.0.0.0' self.user_agent = 'Rails Testing' end + def env + write_cookies! + super + end + def request_method=(method) @env['REQUEST_METHOD'] = method.to_s.upcase end @@ -49,8 +56,19 @@ module ActionDispatch end def accept=(mime_types) - @env.delete("action_dispatch.request.accepts") - @env["HTTP_ACCEPT"] = Array(mime_types).collect { |mime_types| mime_types.to_s }.join(",") + @env.delete('action_dispatch.request.accepts') + @env['HTTP_ACCEPT'] = Array(mime_types).collect { |mime_types| mime_types.to_s }.join(",") end + + def cookies + @cookies ||= super + end + + private + def write_cookies! + unless @cookies.blank? + @env['HTTP_COOKIE'] = @cookies.map { |name, value| "#{name}=#{value};" }.join(' ') + end + end end end -- cgit v1.2.3