1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Attributes can be dup-ed

This commit is contained in:
Ryuta Kamizono 2020-05-06 00:37:35 +09:00
parent 55e038cf17
commit 199e4e96d6
2 changed files with 20 additions and 0 deletions

View file

@ -77,6 +77,11 @@ module ActiveModel
super
end
def initialize_dup(other) # :nodoc:
@attributes = @attributes.deep_dup
super
end
# Returns a hash of all the attributes with their names as keys and the values of the attributes as values.
#
# class Person

View file

@ -108,6 +108,21 @@ module ActiveModel
assert_equal attributes, new_attributes
end
test "attributes can be dup-ed" do
data = ModelForAttributesTest.new
data.integer_field = 1
duped = data.dup
assert_equal 1, data.integer_field
assert_equal 1, duped.integer_field
duped.integer_field = 2
assert_equal 1, data.integer_field
assert_equal 2, duped.integer_field
end
test "can't modify attributes if frozen" do
data = ModelForAttributesTest.new
data.freeze