avoid changing existing environment keys
This commit is contained in:
parent
cd1d3d6e63
commit
55052f83ef
@ -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)
|
||||
if environment.has_key?(ENV_KEY_CUSTOM)
|
||||
@custom = environment[ENV_KEY_CUSTOM]
|
||||
else
|
||||
@custom = {}
|
||||
environment['zero.params.custom'] = @custom
|
||||
environment[ENV_KEY_CUSTOM] = @custom
|
||||
end
|
||||
end
|
||||
|
||||
# get a parameter
|
||||
|
12
spec/unit/request/parameter/initialize_spec.rb
Normal file
12
spec/unit/request/parameter/initialize_spec.rb
Normal 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
|
Loading…
Reference in New Issue
Block a user