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:
parent
6873b1d658
commit
2831996483
2 changed files with 10 additions and 2 deletions
|
@ -37,6 +37,12 @@ module ActiveRecord
|
||||||
hash.merge!(self)
|
hash.merge!(self)
|
||||||
hash
|
hash
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def dup # :nodoc:
|
||||||
|
copy = super
|
||||||
|
copy.types = types.dup
|
||||||
|
copy
|
||||||
|
end
|
||||||
|
|
||||||
# Provides a duplicate with typecasting disabled.
|
# Provides a duplicate with typecasting disabled.
|
||||||
#
|
#
|
||||||
|
|
|
@ -86,12 +86,14 @@ class TypecastingTest < ActiveRecord::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
test "without typecasting" do
|
test "without typecasting" do
|
||||||
|
@attributes.merge!('comments_count' => '5')
|
||||||
attributes = @attributes.without_typecast
|
attributes = @attributes.without_typecast
|
||||||
attributes['comments_count'] = '5'
|
|
||||||
|
|
||||||
assert_equal '5', attributes['comments_count']
|
assert_equal '5', attributes['comments_count']
|
||||||
|
assert_equal 5, @attributes['comments_count'], "Original attributes should typecast"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
test "typecast all attributes" do
|
test "typecast all attributes" do
|
||||||
attributes = @attributes.merge('title' => 'I love sandwiches', 'comments_count' => '5')
|
attributes = @attributes.merge('title' => 'I love sandwiches', 'comments_count' => '5')
|
||||||
attributes.typecast!
|
attributes.typecast!
|
||||||
|
|
Loading…
Reference in a new issue