Skip to content

Commit

Permalink
Deep copy in the superclass merging to ensure no sharing of nested ha…
Browse files Browse the repository at this point in the history
…shes.

Fixes #83
  • Loading branch information
jnunemaker committed Apr 21, 2012
1 parent 939d1d2 commit 682af8f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/httparty/module_inheritable_attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def inherited(subclass)
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
Expand Down
8 changes: 8 additions & 0 deletions spec/httparty_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,14 @@ def self.name
@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"}
Expand Down

1 comment on commit 682af8f

@Sutto
Copy link

@Sutto Sutto commented on 682af8f May 16, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This causes issues on 1.9.3 with the the rails normalizer, since the query normalizer is a proc and hence can't be duplicated. I'll see if I can put together a pull request to fix it.

Please sign in to comment.