Skip to content

Commit

Permalink
on and ON are type casted to a true boolean column
Browse files Browse the repository at this point in the history
  • Loading branch information
spastorino committed Jan 12, 2012
1 parent ffc8e59 commit fc74a51
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
4 changes: 2 additions & 2 deletions activerecord/lib/active_record/connection_adapters/column.rb
Expand Up @@ -5,8 +5,8 @@ module ActiveRecord
module ConnectionAdapters
# An abstract definition of a column in a table.
class Column
TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE'].to_set
FALSE_VALUES = [false, 0, '0', 'f', 'F', 'false', 'FALSE'].to_set
TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE', 'on', 'ON'].to_set
FALSE_VALUES = [false, 0, '0', 'f', 'F', 'false', 'FALSE', 'off', 'OFF'].to_set

module Format
ISO_DATE = /\A(\d{4})-(\d\d)-(\d\d)\z/
Expand Down
29 changes: 29 additions & 0 deletions activerecord/test/cases/column_test.rb
@@ -0,0 +1,29 @@
require "cases/helper"

module ActiveRecord
module ConnectionAdapters
class ColumnTest < ActiveRecord::TestCase
def test_type_cast_boolean
column = Column.new("field", nil, "boolean")
assert column.type_cast(true)
assert column.type_cast(1)
assert column.type_cast('1')
assert column.type_cast('t')
assert column.type_cast('T')
assert column.type_cast('true')
assert column.type_cast('TRUE')
assert column.type_cast('on')
assert column.type_cast('ON')
assert !column.type_cast(false)
assert !column.type_cast(0)
assert !column.type_cast('0')
assert !column.type_cast('f')
assert !column.type_cast('F')
assert !column.type_cast('false')
assert !column.type_cast('FALSE')
assert !column.type_cast('off')
assert !column.type_cast('OFF')
end
end
end
end

0 comments on commit fc74a51

Please sign in to comment.