Skip to content

Instantly share code, notes, and snippets.

@RaVbaker
Created May 14, 2014 10:33
Show Gist options
  • Save RaVbaker/5247552f66bb5d4df6d5 to your computer and use it in GitHub Desktop.
Save RaVbaker/5247552f66bb5d4df6d5 to your computer and use it in GitHub Desktop.
AR.instantiate with hash when keys are symbols bug
# Activate the gem you are reporting the issue against.
gem 'activerecord', '4.1.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: 'sqlite3', database: ':memory:')
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :posts do |t|
t.string :title
end
end
class Post < ActiveRecord::Base
end
class BugTest < Minitest::Test
# this fails
def test_instantiate_hash_with_keys_as_symbols
post = Post.instantiate title: "Hello world!"
assert_equal "Hello world!", post.title
end
# this passes
def test_instantiate_hash_with_keys_as_strings
post = Post.instantiate "title" => "Hello world 2!"
assert_equal "Hello world 2!", post.title
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment