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

Fixed: #without_typecast should only disable typecasting on the duplicated attributes [#3387 state:resolved]

Signed-off-by: Joshua Peek <josh@joshpeek.com>
This commit is contained in:
Eric Chapweske 2009-10-18 10:22:22 -05:00 committed by Joshua Peek
parent 6873b1d658
commit 2831996483
2 changed files with 10 additions and 2 deletions

View file

@ -37,6 +37,12 @@ module ActiveRecord
hash.merge!(self)
hash
end
def dup # :nodoc:
copy = super
copy.types = types.dup
copy
end
# Provides a duplicate with typecasting disabled.
#

View file

@ -86,12 +86,14 @@ class TypecastingTest < ActiveRecord::TestCase
end
test "without typecasting" do
@attributes.merge!('comments_count' => '5')
attributes = @attributes.without_typecast
attributes['comments_count'] = '5'
assert_equal '5', attributes['comments_count']
assert_equal 5, @attributes['comments_count'], "Original attributes should typecast"
end
test "typecast all attributes" do
attributes = @attributes.merge('title' => 'I love sandwiches', 'comments_count' => '5')
attributes.typecast!