-
-
Save imanel/087da70cd147e69d755a to your computer and use it in GitHub Desktop.
Test for deep_munge pull requests
This file contains 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
Output for rails_master.rb | |
Input | Output | |
{:person=>nil} | {:person=>nil} | |
{:person=>[]} | {:person=>nil} | |
{:person=>[]} | {:person=>nil} | |
{:person=>[]} | {:person=>nil} | |
{:person=>["foo"]} | {:person=>["foo"]} | |
Output for pull_11044.rb | |
Input | Output | |
{:person=>nil} | {:person=>nil} | |
{:person=>[]} | {:person=>[]} | |
{:person=>[]} | {:person=>nil} | |
{:person=>[]} | {:person=>nil} | |
{:person=>["foo"]} | {:person=>["foo"]} | |
Output for pull_12251.rb | |
Input | Output | |
{:person=>nil} | {:person=>nil} | |
{:person=>[]} | {:person=>[]} | |
{:person=>[]} | {:person=>[]} | |
{:person=>[]} | {:person=>[]} | |
{:person=>["foo"]} | {:person=>["foo"]} |
This file contains 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
module ActionDispatch | |
class Request < Rack::Request | |
class Utils # :nodoc: | |
class << self | |
# Remove nils from the params hash | |
def deep_munge(hash) | |
hash.each do |k, v| | |
case v | |
when Array | |
v.grep(Hash) { |x| deep_munge(x) } | |
if v.empty? | |
hash[k] = [] | |
else | |
v.compact! | |
hash[k] = nil if v.empty? | |
end | |
when Hash | |
deep_munge(v) | |
end | |
end | |
hash | |
end | |
end | |
end | |
end | |
end |
This file contains 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
module ActionDispatch | |
class Request < Rack::Request | |
class Utils # :nodoc: | |
class << self | |
# Remove nils from the params hash | |
def deep_munge(hash) | |
hash.each do |k, v| | |
case v | |
when Array | |
v.grep(Hash) { |x| deep_munge(x) } | |
v.compact! | |
when Hash | |
deep_munge(v) | |
end | |
end | |
hash | |
end | |
end | |
end | |
end | |
end |
This file contains 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
module ActionDispatch | |
class Request < Rack::Request | |
class Utils # :nodoc: | |
class << self | |
# Remove nils from the params hash | |
def deep_munge(hash) | |
hash.each do |k, v| | |
case v | |
when Array | |
v.grep(Hash) { |x| deep_munge(x) } | |
v.compact! | |
hash[k] = nil if v.empty? | |
when Hash | |
deep_munge(v) | |
end | |
end | |
hash | |
end | |
end | |
end | |
end | |
end |
This file contains 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
#!/usr/bin/env ruby | |
# USAGE | |
# $ ruby tester.rb filename | |
require 'rack/request' | |
require "./#{ARGV.first}" | |
EXAMPLES = [ | |
{ person: nil }, | |
{ person: [] }, | |
{ person: [nil] }, | |
{ person: [nil, nil, nil] }, | |
{ person: ["foo", nil] } | |
] | |
# puts ActionDispatch::Request::Utils.deep_munge(EXAMPLES.first).inspect | |
separator = " | " | |
column_size = 20 | |
puts "Output for #{ARGV.first}" | |
puts "Input".ljust(column_size) + separator + "Output" | |
EXAMPLES.each do |input| | |
output = ActionDispatch::Request::Utils.deep_munge(input.dup) | |
puts input.inspect.ljust(column_size) + separator + output.inspect | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment