1
0
Fork 0
mirror of https://github.com/jnunemaker/httparty synced 2023-03-27 23:23:07 -04:00

Deep copy in the superclass merging to ensure no sharing of nested hashes.

Fixes #83
This commit is contained in:
John Nunemaker 2012-04-21 18:45:03 -04:00
parent 939d1d27c9
commit 682af8fbf6
2 changed files with 9 additions and 1 deletions

View file

@ -22,7 +22,7 @@ module HTTParty
if instance_variable_get(ivar).respond_to?(:merge)
method = <<-EOM
def self.#{inheritable_attribute}
#{ivar} = superclass.#{inheritable_attribute}.merge #{ivar}
#{ivar} = superclass.#{inheritable_attribute}.merge Marshal.load(Marshal.dump(#{ivar}))
end
EOM
subclass.class_eval method

View file

@ -526,6 +526,14 @@ describe HTTParty do
@parent.default_options.should == {:basic_auth => {:username => 'user', :password => 'password'}}
end
it "doesn't modify hashes in the parent's default options" do
@parent.headers 'Accept' => 'application/json'
@child1.headers 'Accept' => 'application/xml'
@parent.default_options[:headers].should == {'Accept' => 'application/json'}
@child1.default_options[:headers].should == {'Accept' => 'application/xml'}
end
it "inherits default_cookies from the parent class" do
@parent.cookies 'type' => 'chocolate_chip'
@child1.default_cookies.should == {"type" => "chocolate_chip"}