Skip to content
This repository
Browse code

on and ON are type casted to a true boolean column

  • Loading branch information...
commit fc74a51c3fd51d33fb4891a1f0c8d4571a776905 1 parent ffc8e59
Santiago Pastorino authored January 11, 2012
4  activerecord/lib/active_record/connection_adapters/column.rb
@@ -5,8 +5,8 @@ module ActiveRecord
5 5
   module ConnectionAdapters
6 6
     # An abstract definition of a column in a table.
7 7
     class Column
8  
-      TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE'].to_set
9  
-      FALSE_VALUES = [false, 0, '0', 'f', 'F', 'false', 'FALSE'].to_set
  8
+      TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE', 'on', 'ON'].to_set
  9
+      FALSE_VALUES = [false, 0, '0', 'f', 'F', 'false', 'FALSE', 'off', 'OFF'].to_set
10 10
 
11 11
       module Format
12 12
         ISO_DATE = /\A(\d{4})-(\d\d)-(\d\d)\z/
29  activerecord/test/cases/column_test.rb
... ...
@@ -0,0 +1,29 @@
  1
+require "cases/helper"
  2
+
  3
+module ActiveRecord
  4
+  module ConnectionAdapters
  5
+    class ColumnTest < ActiveRecord::TestCase
  6
+      def test_type_cast_boolean
  7
+        column = Column.new("field", nil, "boolean")
  8
+        assert column.type_cast(true)
  9
+        assert column.type_cast(1)
  10
+        assert column.type_cast('1')
  11
+        assert column.type_cast('t')
  12
+        assert column.type_cast('T')
  13
+        assert column.type_cast('true')
  14
+        assert column.type_cast('TRUE')
  15
+        assert column.type_cast('on')
  16
+        assert column.type_cast('ON')
  17
+        assert !column.type_cast(false)
  18
+        assert !column.type_cast(0)
  19
+        assert !column.type_cast('0')
  20
+        assert !column.type_cast('f')
  21
+        assert !column.type_cast('F')
  22
+        assert !column.type_cast('false')
  23
+        assert !column.type_cast('FALSE')
  24
+        assert !column.type_cast('off')
  25
+        assert !column.type_cast('OFF')
  26
+      end
  27
+    end
  28
+  end
  29
+end

0 notes on commit fc74a51

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