1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

mysql type cast should return integers when typecasting true / false

This commit is contained in:
Aaron Patterson 2011-04-13 16:05:30 -07:00
parent a0d4c8d1bf
commit a22ceaeefa
3 changed files with 57 additions and 0 deletions

View file

@ -244,6 +244,12 @@ module ActiveRecord
end
end
def type_cast(value, column)
return super unless value == true || value == false
value ? 1 : 0
end
def quote_column_name(name) #:nodoc:
@quoted_column_names[name] ||= "`#{name}`"
end

View file

@ -0,0 +1,26 @@
require "cases/helper"
module ActiveRecord
module ConnectionAdapters
class MysqlAdapter
class QuotingTest < ActiveRecord::TestCase
def setup
@conn = ActiveRecord::Base.connection
end
def test_type_cast_true
c = Column.new(nil, 1, 'boolean')
assert_equal 1, @conn.type_cast(true, nil)
assert_equal 1, @conn.type_cast(true, c)
end
def test_type_cast_false
c = Column.new(nil, 1, 'boolean')
assert_equal 0, @conn.type_cast(false, nil)
assert_equal 0, @conn.type_cast(false, c)
end
end
end
end
end

View file

@ -0,0 +1,25 @@
require "cases/helper"
module ActiveRecord
module ConnectionAdapters
class PostgreSQLAdapter
class QuotingTest < ActiveRecord::TestCase
def setup
@conn = ActiveRecord::Base.connection
end
def test_type_cast_true
c = Column.new(nil, 1, 'boolean')
assert_equal 't', @conn.type_cast(true, nil)
assert_equal 't', @conn.type_cast(true, c)
end
def test_type_cast_false
c = Column.new(nil, 1, 'boolean')
assert_equal 'f', @conn.type_cast(false, nil)
assert_equal 'f', @conn.type_cast(false, c)
end
end
end
end
end