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:
parent
a0d4c8d1bf
commit
a22ceaeefa
3 changed files with 57 additions and 0 deletions
|
@ -244,6 +244,12 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def type_cast(value, column)
|
||||||
|
return super unless value == true || value == false
|
||||||
|
|
||||||
|
value ? 1 : 0
|
||||||
|
end
|
||||||
|
|
||||||
def quote_column_name(name) #:nodoc:
|
def quote_column_name(name) #:nodoc:
|
||||||
@quoted_column_names[name] ||= "`#{name}`"
|
@quoted_column_names[name] ||= "`#{name}`"
|
||||||
end
|
end
|
||||||
|
|
26
activerecord/test/cases/adapters/mysql/quoting_test.rb
Normal file
26
activerecord/test/cases/adapters/mysql/quoting_test.rb
Normal 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
|
||||||
|
|
25
activerecord/test/cases/adapters/postgresql/quoting_test.rb
Normal file
25
activerecord/test/cases/adapters/postgresql/quoting_test.rb
Normal 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
|
Loading…
Reference in a new issue