Last active
April 20, 2018 04:26
-
-
Save trliner/8e10e326095437618a6dce132299d0ce to your computer and use it in GitHub Desktop.
Test case for expected behavior of to_json's :only option.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
begin | |
require "bundler/inline" | |
rescue LoadError => e | |
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler" | |
raise e | |
end | |
gemfile(true) do | |
source "https://rubygems.org" | |
git_source(:github) { |repo| "https://github.com/#{repo}.git" } | |
gem "rails", github: "rails/rails" | |
end | |
require "active_support" | |
require "active_support/core_ext/object/blank" | |
require "minitest/autorun" | |
class BugTest < Minitest::Test | |
def test_nested_hash_json_key_filtering | |
nested_hash = { hash: { key: 'value' }, array: [{ key: 'value' }] } | |
assert_equal nested_hash.as_json(only: [:hash]), { hash: { key: 'value' } } | |
assert_equal nested_hash.as_json(only: [:array]), { array: [{ key: 'value' }] } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment