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

Merge pull request #17680 from larskanis/fix_bytea_change_detection

PostgreSQL, Fix change detection caused by superfluous bytea unescaping
This commit is contained in:
Sean Griffin 2014-12-30 13:33:42 -07:00
commit 322750e213
2 changed files with 9 additions and 1 deletions

View file

@ -5,6 +5,7 @@ module ActiveRecord
class Bytea < Type::Binary # :nodoc: class Bytea < Type::Binary # :nodoc:
def type_cast_from_database(value) def type_cast_from_database(value)
return if value.nil? return if value.nil?
return value.to_s if value.is_a?(Type::Binary::Data)
PGconn.unescape_bytea(super) PGconn.unescape_bytea(super)
end end
end end

View file

@ -688,7 +688,14 @@ class DirtyTest < ActiveRecord::TestCase
serialize :data serialize :data
end end
klass.create!(data: "foo") binary = klass.create!(data: "\\\\foo")
assert_not binary.changed?
binary.data = binary.data.dup
assert_not binary.changed?
binary = klass.last binary = klass.last
assert_not binary.changed? assert_not binary.changed?