From 432b2b29dad9dbc6aef57017dda1146baef74bc7 Mon Sep 17 00:00:00 2001 From: Stephan Kaag Date: Wed, 9 Jul 2014 14:04:32 +0200 Subject: [PATCH] Fix bug where default_options are unexpectedly modified --- lib/httparty.rb | 2 +- spec/httparty_spec.rb | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/httparty.rb b/lib/httparty.rb index acf93d0..8b49c58 100644 --- a/lib/httparty.rb +++ b/lib/httparty.rb @@ -515,7 +515,7 @@ module HTTParty private def perform_request(http_method, path, options, &block) #:nodoc: - options = default_options.merge(options) + options = ModuleInheritableAttributes.hash_deep_dup(default_options).merge(options) process_headers(options) process_cookies(options) Request.new(http_method, path, options).perform(&block) diff --git a/spec/httparty_spec.rb b/spec/httparty_spec.rb index e0ba10b..55a159e 100644 --- a/spec/httparty_spec.rb +++ b/spec/httparty_spec.rb @@ -186,6 +186,13 @@ describe HTTParty do @klass.get('', cookies: {type: 'snickerdoodle'}) end + it 'doesnt modify default_options' do + @klass.headers.should == {} + expect_headers('cookie' => 'type=snickerdoodle') + @klass.get('', cookies: {type: 'snickerdoodle'}) + @klass.default_options[:headers].should == {} + end + it 'adds optional cookies to the optional headers' do expect_headers(baz: 'spax', 'cookie' => 'type=snickerdoodle') @klass.get('', cookies: {type: 'snickerdoodle'}, headers: {baz: 'spax'})