public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Revert "coerce blank strings to nil values for boolean and integer fields"

This reverts commit aee14630d4dc0856e597794cc731fac68c2d2e34.

[#860 state:incomplete]
jeremy (author)
Thu Aug 21 21:34:17 -0700 2008
commit  a5eb297424f68583636b762686726bc0c84703c0
tree    50a4f35009f4c53f6898105666ab6eed6d361828
parent  e6a66cbd056f177f7e60341799aa95791fcfa19d
...
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
 
 
 
 
 
2583
2584
2585
...
2572
2573
2574
 
 
 
 
 
 
 
 
2575
2576
2577
2578
2579
2580
2581
2582
0
@@ -2572,14 +2572,11 @@ module ActiveRecord #:nodoc:
0
       end
0
 
0
       def convert_number_column_value(value)
0
-        if value == false
0
-          0
0
-        elsif value == true
0
-          1
0
-        elsif value.is_a?(String) && value.blank?
0
-          nil
0
-        else
0
-          value
0
+        case value
0
+          when FalseClass; 0
0
+          when TrueClass;  1
0
+          when '';         nil
0
+          else value
0
         end
0
       end
0
 
...
138
139
140
141
142
143
144
145
 
146
147
148
...
138
139
140
 
 
 
 
 
141
142
143
144
0
@@ -138,11 +138,7 @@ module ActiveRecord
0
 
0
         # convert something to a boolean
0
         def value_to_boolean(value)
0
-          if value.blank?
0
-            nil
0
-          else
0
-            TRUE_VALUES.include?(value)
0
-          end
0
+          TRUE_VALUES.include?(value)
0
         end
0
 
0
         # convert something to a BigDecimal
...
1420
1421
1422
1423
1424
 
 
1425
1426
1427
...
1434
1435
1436
1437
1438
 
 
1439
1440
1441
...
1420
1421
1422
 
 
1423
1424
1425
1426
1427
...
1434
1435
1436
 
 
1437
1438
1439
1440
1441
0
@@ -1420,8 +1420,8 @@ class ValidatesNumericalityTest < ActiveRecord::TestCase
0
   def test_validates_numericality_of_with_nil_allowed
0
     Topic.validates_numericality_of :approved, :allow_nil => true
0
 
0
-    invalid!(JUNK)
0
-    valid!(NIL + BLANK + FLOATS + INTEGERS + BIGDECIMAL + INFINITY)
0
+    invalid!(BLANK + JUNK)
0
+    valid!(NIL + FLOATS + INTEGERS + BIGDECIMAL + INFINITY)
0
   end
0
 
0
   def test_validates_numericality_of_with_integer_only
0
@@ -1434,8 +1434,8 @@ class ValidatesNumericalityTest < ActiveRecord::TestCase
0
   def test_validates_numericality_of_with_integer_only_and_nil_allowed
0
     Topic.validates_numericality_of :approved, :only_integer => true, :allow_nil => true
0
 
0
-    invalid!(JUNK + FLOATS + BIGDECIMAL + INFINITY)
0
-    valid!(NIL + BLANK + INTEGERS)
0
+    invalid!(BLANK + JUNK + FLOATS + BIGDECIMAL + INFINITY)
0
+    valid!(NIL + INTEGERS)
0
   end
0
 
0
   def test_validates_numericality_with_greater_than

Comments