mirror of
https://github.com/jnunemaker/httparty
synced 2023-03-27 23:23:07 -04:00
Fix inheritable attributes mutable by subclasses
child classes should be able to reconfigure inherited attributes without stomping each other
This commit is contained in:
parent
a004f82e6d
commit
33da531269
2 changed files with 24 additions and 3 deletions
|
@ -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
|
||||
end
|
||||
|
|
|
@ -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')
|
||||
|
|
Loading…
Reference in a new issue