Skip to content
This repository
Browse code

Merge pull request #4558 from stephencelis/type-cast-unknown-should-fail

Don't type-cast unknown types to YAML.
  • Loading branch information...
commit 01176a7eaf40577e298b2c6e120e3fa17feabcc7 2 parents 47addcc + 920070e
Aaron Patterson authored January 23, 2012
2  activerecord/lib/active_record/connection_adapters/abstract/quoting.rb
@@ -71,7 +71,7 @@ def type_cast(value, column)
71 71
         when Date, Time then quoted_date(value)
72 72
         when Symbol     then value.to_s
73 73
         else
74  
-          YAML.dump(value)
  74
+          raise TypeError, "can't cast #{value.class} to #{column.type}"
75 75
         end
76 76
       end
77 77
 
4  activerecord/test/cases/adapters/sqlite3/quoting_test.rb
@@ -70,9 +70,9 @@ def test_type_cast_bigdecimal
70 70
           assert_equal bd.to_f, @conn.type_cast(bd, nil)
71 71
         end
72 72
 
73  
-        def test_type_cast_unknown
  73
+        def test_type_cast_unknown_should_raise_error
74 74
           obj = Class.new.new
75  
-          assert_equal YAML.dump(obj), @conn.type_cast(obj, nil)
  75
+          assert_raise(TypeError) { @conn.type_cast(obj, nil) }
76 76
         end
77 77
 
78 78
         def test_quoted_id
8  activerecord/test/cases/base_test.rb
@@ -992,10 +992,9 @@ def test_dup
992 992
     assert_equal "b", duped_topic.title
993 993
 
994 994
     # test if the attribute values have been duped
995  
-    topic.title = {"a" => "b"}
996 995
     duped_topic = topic.dup
997  
-    duped_topic.title["a"] = "c"
998  
-    assert_equal "b", topic.title["a"]
  996
+    duped_topic.title.replace "c"
  997
+    assert_equal "a", topic.title
999 998
 
1000 999
     # test if attributes set as part of after_initialize are duped correctly
1001 1000
     assert_equal topic.author_email_address, duped_topic.author_email_address
@@ -1006,8 +1005,7 @@ def test_dup
1006 1005
     assert_not_equal duped_topic.id, topic.id
1007 1006
 
1008 1007
     duped_topic.reload
1009  
-    # FIXME: I think this is poor behavior, and will fix it with #5686
1010  
-    assert_equal({'a' => 'c'}.to_yaml, duped_topic.title)
  1008
+    assert_equal("c", duped_topic.title)
1011 1009
   end
1012 1010
 
1013 1011
   def test_dup_with_aggregate_of_same_name_as_attribute

1 note on commit 01176a7

Arun Agrawal
Collaborator

Seems after this Build is broken :-(

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