only log an error if there is a logger. fixes #5226

Conflicts:

	activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
This commit is contained in:
Aaron Patterson
2012-03-02 10:25:00 -08:00
parent 8674823350
commit af02291871
3 changed files with 11 additions and 2 deletions

View File

@@ -54,7 +54,7 @@ module ActiveRecord
define_callbacks :checkout, :checkin
attr_accessor :visitor, :pool
attr_reader :schema_cache, :last_use, :in_use
attr_reader :schema_cache, :last_use, :in_use, :logger
alias :in_use? :in_use
def initialize(connection, logger = nil, pool = nil) #:nodoc:

View File

@@ -204,7 +204,7 @@ module ActiveRecord
value = super
if column.type == :string && value.encoding == Encoding::ASCII_8BIT
@logger.error "Binary data inserted for `string` type on column `#{column.name}`"
logger.error "Binary data inserted for `string` type on column `#{column.name}`" if logger
value.encode! 'utf-8'
end
value

View File

@@ -1,6 +1,7 @@
require "cases/helper"
require 'bigdecimal'
require 'yaml'
require 'securerandom'
module ActiveRecord
module ConnectionAdapters
@@ -12,6 +13,14 @@ module ActiveRecord
:timeout => 100
end
def test_type_cast_binary_encoding_without_logger
@conn.extend(Module.new { def logger; end })
column = Struct.new(:type, :name).new(:string, "foo")
binary = SecureRandom.hex
expected = binary.dup.encode!('utf-8')
assert_equal expected, @conn.type_cast(binary, column)
end
def test_type_cast_symbol
assert_equal 'foo', @conn.type_cast(:foo, nil)
end