Skip to content

Commit

Permalink
only log an error if there is a logger. fixes #5226
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Mar 2, 2012
1 parent 0e94208 commit b5c939d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
Expand Up @@ -57,7 +57,7 @@ class AbstractAdapter
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:
Expand Down
Expand Up @@ -202,7 +202,7 @@ def type_cast(value, column) # :nodoc:

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
Expand Down
9 changes: 9 additions & 0 deletions activerecord/test/cases/adapters/sqlite3/quoting_test.rb
@@ -1,6 +1,7 @@
require "cases/helper"
require 'bigdecimal'
require 'yaml'
require 'securerandom'

module ActiveRecord
module ConnectionAdapters
Expand All @@ -12,6 +13,14 @@ def setup
: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
Expand Down

0 comments on commit b5c939d

Please sign in to comment.