Last active
August 29, 2015 14:10
-
-
Save larskanis/d007b9d84aaa5ebce358 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem 'activerecord', '4.2.0.beta4' | |
# gem 'activerecord', '4.1.8' | |
# gem 'activerecord', '4.0.12' | |
gem 'pg', '0.18.0.pre20141117110243' | |
# gem 'pg', '0.17.1' | |
require 'active_record' | |
require 'minitest/autorun' | |
require 'logger' | |
# Ensure backward compatibility with Minitest 4 | |
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test) | |
# This connection will do for database-independent bug reports. | |
ActiveRecord::Base.establish_connection(adapter: 'postgresql') | |
ActiveRecord::Base.logger = Logger.new(STDOUT) | |
ActiveRecord::Schema.define do | |
create_table :binaries, force: true do |t| | |
t.binary :data | |
end | |
end | |
class Binary < ActiveRecord::Base | |
end | |
class BugTest < Minitest::Test | |
# This succeeds on all rails and pg versions | |
def test_text_only | |
post = Binary.create! data: 'test' | |
assert !post.changed?, "succeeds, because of text only" | |
post.data = 'test' | |
assert !post.changed?, "succeeds, because text only change" | |
end | |
def test_backslash | |
post = Binary.create! data: '\\\\foo' | |
assert !post.changed?, "signals change on rails-4.2.0.beta4, because of unescaping binary data" | |
post.data = '\\\\foo' | |
# This fails on rails versions >= 4.0 | |
assert !post.changed?, "nothing changed, but fails nevertheless" | |
end | |
def test_null_byte | |
# This gives 'ArgumentError: string contains null byte' in unescape_bytea | |
# with pg-0.18.0.pre20141117110243 | |
post = Binary.create! data: '\0' | |
assert !post.changed?, "signals change on rails-4.2.0.beta4, because of unescaping binary data" | |
post.data = '\0' | |
# This fails on rails versions >= 4.0 | |
assert !post.changed?, "nothing changed, but fails nevertheless" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment