Skip to content
Browse files

Fixed: #without_typecast should only disable typecasting on the dupli…

…cated attributes [#3387 state:resolved]

Signed-off-by: Joshua Peek <josh@joshpeek.com>
  • Loading branch information...
1 parent 6873b1d commit 2831996483c6a045f1f38d8030256eb58d9771c3 @eac eac committed with josh Oct 18, 2009
View
6 activerecord/lib/active_record/attributes/typecasting.rb
@@ -37,6 +37,12 @@ def to_h
hash.merge!(self)
hash
end
+
+ def dup # :nodoc:
+ copy = super
+ copy.types = types.dup
+ copy
+ end
# Provides a duplicate with typecasting disabled.
#
View
6 activerecord/test/cases/attributes/typecasting_test.rb
@@ -86,12 +86,14 @@ def setup
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!

0 comments on commit 2831996

Please sign in to comment.
Something went wrong with that request. Please try again.