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:
parent
939d1d27c9
commit
682af8fbf6
2 changed files with 9 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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"}
|
||||
|
|
Loading…
Add table
Reference in a new issue