mirror of
https://github.com/github/rails.git
synced 2026-04-04 03:00:58 -04:00
Fix issue with #class_inheritable_accessor saving updates to the parent class when initialized with an Array or Hash [mojombo]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5218 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
*SVN*
|
||||
|
||||
* Fix issue with #class_inheritable_accessor saving updates to the parent class when initialized with an Array or Hash [mojombo]
|
||||
|
||||
* Hash#to_xml supports Bignum and BigDecimal. #6313 [edibiase]
|
||||
|
||||
* Don't undefine #class in OptionMerger [Rick]
|
||||
|
||||
@@ -107,7 +107,12 @@ class Class # :nodoc:
|
||||
private
|
||||
def inherited_with_inheritable_attributes(child)
|
||||
inherited_without_inheritable_attributes(child) if respond_to?(:inherited_without_inheritable_attributes)
|
||||
child.instance_variable_set('@inheritable_attributes', inheritable_attributes.dup)
|
||||
|
||||
new_inheritable_attributes = inheritable_attributes.inject({}) do |memo, (key, value)|
|
||||
memo.update(key => (value.dup rescue value))
|
||||
end
|
||||
|
||||
child.instance_variable_set('@inheritable_attributes', new_inheritable_attributes)
|
||||
end
|
||||
|
||||
alias inherited_without_inheritable_attributes inherited
|
||||
|
||||
@@ -137,4 +137,34 @@ class ClassInheritableAttributesTest < Test::Unit::TestCase
|
||||
assert_equal 'b', @klass.b
|
||||
assert_equal 'B', @sub.b
|
||||
end
|
||||
|
||||
def test_array_inheritance
|
||||
@klass.class_inheritable_accessor :a
|
||||
@klass.a = []
|
||||
|
||||
@sub = eval("class SubbyArray < @klass; end; SubbyArray")
|
||||
|
||||
assert_equal [], @klass.a
|
||||
assert_equal [], @sub.a
|
||||
|
||||
@sub.a << :first
|
||||
|
||||
assert_equal [:first], @sub.a
|
||||
assert_equal [], @klass.a
|
||||
end
|
||||
|
||||
def test_array_inheritance
|
||||
@klass.class_inheritable_accessor :a
|
||||
@klass.a = {}
|
||||
|
||||
@sub = eval("class SubbyHash < @klass; end; SubbyHash")
|
||||
|
||||
assert_equal Hash.new, @klass.a
|
||||
assert_equal Hash.new, @sub.a
|
||||
|
||||
@sub.a[:first] = :first
|
||||
|
||||
assert_equal 1, @sub.a.keys.size
|
||||
assert_equal 0, @klass.a.keys.size
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user