Skip to content

Instantly share code, notes, and snippets.

@dnrce
Last active August 29, 2015 14:09
Show Gist options
  • Select an option

  • Save dnrce/fd069844ea1b135bcd37 to your computer and use it in GitHub Desktop.

Select an option

Save dnrce/fd069844ea1b135bcd37 to your computer and use it in GitHub Desktop.
ActiveRecord boolean-in-string behavior change
gem 'activerecord', '4.2.0.beta4'
require 'active_record'
require 'active_record/fixtures'
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: 'sqlite3', database: ':memory:')
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :foos do |t|
t.string :bar
end
end
class Foo < ActiveRecord::Base
end
class BugTest < Minitest::Test
def test_boolean_true
foo = Foo.create(bar: true)
assert_equal true, foo.bar
foo.reload
assert_equal 't', foo.bar
end
def test_boolean_false
foo = Foo.create(bar: false)
assert_equal false, foo.bar
foo.reload
assert_equal 'f', foo.bar
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment