aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/json_serialization_test.rb
diff options
context:
space:
mode:
authorIsaac Betesh <iybetesh@gmail.com>2017-02-08 11:20:38 -0500
committerIsaac Betesh <iybetesh@gmail.com>2017-02-08 12:03:59 -0500
commitc01f31f43c870bd9a828ae96207de0c2cdd8fd08 (patch)
tree8aa50d9d67753781ef638b659d99435b8be1c52b /activerecord/test/cases/json_serialization_test.rb
parent47113df0341cd7bf56056bc666527978c586c7c5 (diff)
downloadrails-c01f31f43c870bd9a828ae96207de0c2cdd8fd08.tar.gz
rails-c01f31f43c870bd9a828ae96207de0c2cdd8fd08.tar.bz2
rails-c01f31f43c870bd9a828ae96207de0c2cdd8fd08.zip
Allow ActiveRecord::Base.as_json to accept a frozen Hash
Diffstat (limited to 'activerecord/test/cases/json_serialization_test.rb')
-rw-r--r--activerecord/test/cases/json_serialization_test.rb11
1 files changed, 11 insertions, 0 deletions
diff --git a/activerecord/test/cases/json_serialization_test.rb b/activerecord/test/cases/json_serialization_test.rb
index 155e858822..5a1d066aef 100644
--- a/activerecord/test/cases/json_serialization_test.rb
+++ b/activerecord/test/cases/json_serialization_test.rb
@@ -101,6 +101,17 @@ class JsonSerializationTest < ActiveRecord::TestCase
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))