Permalink
Browse files

Ensure we actually dup on certain values.

  • Loading branch information...
Sutto committed Jun 9, 2012
1 parent bf646b4 commit b4a65a641b4af5665175c054589181daea88e333
Showing with 14 additions and 4 deletions.
  1. +3 −2 lib/httparty/module_inheritable_attributes.rb
  2. +11 −2 spec/httparty_spec.rb
@@ -35,11 +35,12 @@ def inherited(subclass)
super
@mattr_inheritable_attrs.each do |inheritable_attribute|
ivar = "@#{inheritable_attribute}"
- subclass.instance_variable_set(ivar, instance_variable_get(ivar).clone)
+ # Initially, set the instance variable value to be a clone of the parents value.
+ subclass.instance_variable_set ivar, HTTParty::ModuleInheritableAttributes.deep_clone(instance_variable_get(ivar))
if instance_variable_get(ivar).respond_to?(:merge)
method = <<-EOM
def self.#{inheritable_attribute}
- #{ivar} = superclass.#{inheritable_attribute}.merge HTTParty::ModuleInheritableAttributes.deep_clone(#{ivar})
+ #{ivar} = (superclass.#{inheritable_attribute}.merge(HTTParty::ModuleInheritableAttributes.deep_clone(#{ivar})))
end
EOM
subclass.class_eval method
View
@@ -540,8 +540,17 @@ def self.name
end
it "works with lambda values" do
- @child1.disable_rails_query_string_format
- @child1.default_options[:query_string_normalizer].should be_a Proc
+ @child1.default_options[:imaginary_option] = lambda { "This is a new lambda "}
+ @child1.default_options[:imaginary_option].should be_a Proc
+ end
+
+ it 'should dup the proc on the child class' do
+ imaginary_option = lambda { "This is a new lambda" }
+ @parent.default_options[:imaginary_option] = imaginary_option
+ @parent.default_options[:imaginary_option].should be_equal imaginary_option
+ @child1.default_options[:imaginary_option]
+ @child1.default_options[:imaginary_option].should == imaginary_option
+ @child1.default_options[:imaginary_option].should_not be_equal imaginary_option
end
it "inherits default_cookies from the parent class" do

0 comments on commit b4a65a6

Please sign in to comment.