Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

Conflicts:

	activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb

Conflicts:

	activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
  • Loading branch information...
commit b1358c8fa1d875bdeb0639baab1dc91ed39ac175 1 parent 66c6c7f
@tenderlove tenderlove authored
View
1  activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
@@ -40,6 +40,7 @@ class AbstractAdapter
define_callbacks :checkout, :checkin
attr_accessor :visitor
+ attr_reader :logger
def initialize(connection, logger = nil) #:nodoc:
@active = nil
View
2  activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
@@ -215,7 +215,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
View
9 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
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.