Skip to content

Instantly share code, notes, and snippets.

@hundredwatt
Last active January 4, 2016 19:30
Show Gist options
  • Save hundredwatt/8668163 to your computer and use it in GitHub Desktop.
Save hundredwatt/8668163 to your computer and use it in GitHub Desktop.
ActiveRecord::Store - no implicit conversion of ActiveSupport::HashWithIndifferentAccess into String
# Activate the gem you are reporting the issue against.
gem 'activerecord', '4.0.2'
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.text :data
end
end
class Post < ActiveRecord::Base
store :data, accessors: [:information], coder: JSON
end
class StoreBugTest < Minitest::Test
def test_without_setting_any_accessors
post = Post.create!
dumped = YAML.dump post
loaded = YAML.load dumped
YAML.dump loaded #passes
end
def test_with_setting_accessors
post = Post.create!(information: 'important stuff')
dumped = YAML.dump post
loaded = YAML.load dumped
YAML.dump loaded #fails
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment