diff --git a/lib/httparty/module_inheritable_attributes.rb b/lib/httparty/module_inheritable_attributes.rb index 0afe608..ebb4bb2 100644 --- a/lib/httparty/module_inheritable_attributes.rb +++ b/lib/httparty/module_inheritable_attributes.rb @@ -16,10 +16,10 @@ module HTTParty def inherited(subclass) @mattr_inheritable_attrs.each do |inheritable_attribute| - instance_var = "@#{inheritable_attribute}" - subclass.instance_variable_set(instance_var, instance_variable_get(instance_var)) + instance_var = "@#{inheritable_attribute}" + subclass.instance_variable_set(instance_var, instance_variable_get(instance_var).clone) end end end end -end \ No newline at end of file +end diff --git a/spec/httparty_spec.rb b/spec/httparty_spec.rb index 140e137..718c2c6 100644 --- a/spec/httparty_spec.rb +++ b/spec/httparty_spec.rb @@ -308,6 +308,27 @@ describe HTTParty do end end + describe "two child classes inheriting from one parent" do + before(:each) do + @parent = Class.new do + include HTTParty + end + + @child1 = Class.new(@parent) + @child2 = Class.new(@parent) + end + + it "does not modify each others inherited attributes" do + @child1.default_params :joe => "alive" + @child2.default_params :joe => "dead" + + @child1.default_options.should == { :default_params => {:joe => "alive"} } + @child2.default_options.should == { :default_params => {:joe => "dead"} } + + @parent.default_options.should == { } + end + end + describe "#get" do it "should be able to get html" do stub_http_response_with('google.html')