diff options
author | Jon Moss <me@jonathanmoss.me> | 2016-05-10 15:42:07 -0400 |
---|---|---|
committer | Jon Moss <me@jonathanmoss.me> | 2016-05-10 15:42:07 -0400 |
commit | c650341573243307fbe6f63702a9a4e4e289cfcd (patch) | |
tree | 837f034952378269f05f9cf93f05f0a17e4632dc /activerecord/test | |
parent | 932655a4ef61083da98724bb612d00f89e153c46 (diff) | |
download | rails-c650341573243307fbe6f63702a9a4e4e289cfcd.tar.gz rails-c650341573243307fbe6f63702a9a4e4e289cfcd.tar.bz2 rails-c650341573243307fbe6f63702a9a4e4e289cfcd.zip |
Fix ActiveRecord::LogSubscriber edge case
If an attribute was of the binary type, and also was a Hash, it would
previously not be logged, and instead raise an error saying that
`bytesize` was not defined for the `attribute.value` (a `Hash`).
Now, as is done on 4-2-stable, the attribute's database value is
`bytesize`d, and then logged out to the terminal.
Reproduction script:
```ruby
require 'active_record'
require 'minitest/autorun'
require 'logger'
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :posts, force: true do |t|
t.binary :preferences
end
end
class Post < ActiveRecord::Base
serialize :preferences
end
class BugTest < Minitest::Test
def test_24955
Post.create!(preferences: {a: 1})
assert_equal 1, Post.count
end
end
```
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/log_subscriber_test.rb | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/activerecord/test/cases/log_subscriber_test.rb b/activerecord/test/cases/log_subscriber_test.rb index 707a2d1da1..c97960a412 100644 --- a/activerecord/test/cases/log_subscriber_test.rb +++ b/activerecord/test/cases/log_subscriber_test.rb @@ -215,5 +215,11 @@ class LogSubscriberTest < ActiveRecord::TestCase wait assert_match(/<16 bytes of binary data>/, @logger.logged(:debug).join) end + + def test_binary_data_hash + Binary.create(data: { a: 1 }) + wait + assert_match(/<7 bytes of binary data>/, @logger.logged(:debug).join) + end end end |