0
0
Fork 0

avoid changing existing environment keys

This commit is contained in:
Gibheer 2012-12-01 07:23:37 +01:00
parent cd1d3d6e63
commit 55052f83ef
2 changed files with 20 additions and 2 deletions

View File

@ -12,6 +12,8 @@ module Zero
ENV_KEY_QUERY = 'QUERY_STRING'
# the key for the payload
ENV_KEY_PAYLOAD = 'rack.input'
# the key for custom parameters
ENV_KEY_CUSTOM = 'zero.params.custom'
# the key for the content type
ENV_KEY_CONTENT_TYPE = 'CONTENT_TYPE'
# all content types which used for using the body as a parameter input
@ -40,8 +42,12 @@ module Zero
def initialize(environment)
@query = extract_query_params(environment)
@payload = extract_payload_params(environment)
@custom = {}
environment['zero.params.custom'] = @custom
if environment.has_key?(ENV_KEY_CUSTOM)
@custom = environment[ENV_KEY_CUSTOM]
else
@custom = {}
environment[ENV_KEY_CUSTOM] = @custom
end
end
# get a parameter

View File

@ -0,0 +1,12 @@
require 'spec_helper'
describe Zero::Request::Parameter, '#initialize' do
subject { Zero::Request::Parameter.new(env) }
let(:env) { EnvGenerator.get('/get', {
'zero.params.custom' => {'foo' => 'bar'} }) }
it 'does not overwrite parameters' do
subject
expect(env['zero.params.custom']).to have_key('foo')
end
end