Skip to content

Commit

Permalink
Fixed: #without_typecast should only disable typecasting on the dupli…
Browse files Browse the repository at this point in the history
…cated attributes [#3387 state:resolved]

Signed-off-by: Joshua Peek <josh@joshpeek.com>
  • Loading branch information
Eric Chapweske authored and josh committed Oct 18, 2009
1 parent 6873b1d commit 2831996
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 6 additions & 0 deletions activerecord/lib/active_record/attributes/typecasting.rb
Expand Up @@ -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.
#
Expand Down
6 changes: 4 additions & 2 deletions activerecord/test/cases/attributes/typecasting_test.rb
Expand Up @@ -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!
Expand Down

0 comments on commit 2831996

Please sign in to comment.