Skip to content

Commit

Permalink
Make process reuse the env var passed as argument
Browse files Browse the repository at this point in the history
  • Loading branch information
spastorino committed Apr 6, 2011
1 parent 0c5aded commit 0e4748c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
9 changes: 4 additions & 5 deletions actionpack/lib/action_dispatch/testing/integration.rb
Expand Up @@ -243,7 +243,8 @@ def _mock_session
end

# Performs the actual request.
def process(method, path, parameters = nil, rack_environment = nil)
def process(method, path, parameters = nil, env = nil)
env ||= {}
if path =~ %r{://}
location = URI.parse(path)
https! URI::HTTPS === location if location.scheme
Expand All @@ -259,7 +260,7 @@ def process(method, path, parameters = nil, rack_environment = nil)

hostname, port = host.split(':')

env = {
default_env = {
:method => method,
:params => parameters,

Expand All @@ -277,9 +278,7 @@ def process(method, path, parameters = nil, rack_environment = nil)

session = Rack::Test::Session.new(_mock_session)

(rack_environment || {}).each do |key, value|
env[key] = value
end
env.reverse_merge!(default_env)

This comment has been minimized.

Copy link
@dolzenko

dolzenko Sep 19, 2011

Contributor

This destructively modifies parameters passed into process and in turn into get/put//etc. methods - not good :)

This comment has been minimized.

Copy link
@spastorino

spastorino Sep 24, 2011

Author Contributor

@dolzenko you're right. Can you provide a test case and patch?. Thanks.

This comment has been minimized.

Copy link
@spastorino

spastorino Sep 24, 2011

Author Contributor

Fixed 3de95fd


# NOTE: rack-test v0.5 doesn't build a default uri correctly
# Make sure requested path is always a full uri
Expand Down
8 changes: 8 additions & 0 deletions actionpack/test/controller/integration_test.rb
Expand Up @@ -521,4 +521,12 @@ def app
get '/foo'
assert_raise(NameError) { missing_path }
end

test "process reuse the env we pass as argument" do
env = { :SERVER_NAME => 'server', 'action_dispatch.custom' => 'custom' }
get '/foo', nil, env
assert_equal :get, env[:method]
assert_equal 'server', env[:SERVER_NAME]
assert_equal 'custom', env['action_dispatch.custom']
end
end

0 comments on commit 0e4748c

Please sign in to comment.