提交 c01f31f4 编写于 作者: I Isaac Betesh

Allow ActiveRecord::Base.as_json to accept a frozen Hash

上级 47113df0
* Allow ActiveRecord::Base#as_json to be passed a frozen Hash.
*Isaac Betesh*
* Deprecate locking records with unpersisted changes.
*Marc Schütz*
......
......@@ -9,7 +9,7 @@ module Serialization
end
def serializable_hash(options = nil)
options = options.try(:clone) || {}
options = options.try(:dup) || {}
options[:except] = Array(options[:except]).map(&:to_s)
options[:except] |= Array(self.class.inheritance_column)
......
......@@ -101,6 +101,17 @@ def @contact.favorite_quote; "Constraints are liberating"; end
assert_match %r{"favorite_quote":"Constraints are liberating"}, methods_json
end
def test_uses_serializable_hash_with_frozen_hash
def @contact.serializable_hash(options = nil)
super({ only: %w(name) }.freeze)
end
json = @contact.to_json
assert_match %r{"name":"Konata Izumi"}, json
assert_no_match %r{awesome}, json
assert_no_match %r{age}, json
end
def test_uses_serializable_hash_with_only_option
def @contact.serializable_hash(options = nil)
super(only: %w(name))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册