Created
January 27, 2009 21:36
-
-
Save mtodd/53568 to your computer and use it in GitHub Desktop.
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
# Rack Nested Params Parser Spec | |
Rack::Utils.parse_query("x[y][z]=10"). | |
should.equal "x" => {"y" => {"z" => "10"}} | |
Rack::Utils.parse_query("x[y][z][]=10"). | |
should.equal "x" => {"y" => {"z" => ["10"]}} | |
Rack::Utils.parse_query("x[y][z][]=10&x[y][z][]=5"). | |
should.equal "x" => {"y" => {"z" => ["10", "5"]}} | |
Rack::Utils.parse_query("x[y][][z]=10"). | |
should.equal "x" => {"y" => [{"z" => "10"}]} | |
Rack::Utils.parse_query("x[y][][z]=10&x[y][][w]=10"). | |
should.equal "x" => {"y" => [{"z" => "10", "w" => "10"}]} | |
Rack::Utils.parse_query("x[y][][v][w]=10"). | |
should.equal "x" => {"y" => [{"v" => {"w" => "10"}}]} | |
Rack::Utils.parse_query("x[y][][z]=10&x[y][][v][w]=10"). | |
should.equal "x" => {"y" => [{"z" => "10", "v" => {"w" => "10"}}]} | |
Rack::Utils.parse_query("x[y][][z]=10&x[y][][z]=20"). | |
should.equal "x" => {"y" => [{"z" => "10"}, {"z" => "20"}]} | |
Rack::Utils.parse_query("x[y][][z]=10&x[y][][w]=a&x[y][][z]=20&x[y][][w]=b"). | |
should.equal "x" => {"y" => [{"z" => "10", "w" => "a"}, {"z" => "20", "w" => "b"}]} | |
Rack::Utils.parse_query("foo=bar&baz="). | |
should.equal "foo" => "bar", "baz" => "" | |
Rack::Utils.parse_query("foo=bar"). | |
should.equal "foo" => "bar" | |
Rack::Utils.parse_query("foo=bar&foo=baz"). | |
should.equal "foo" => ["bar", "baz"] | |
Rack::Utils.parse_query("foo[]=bar"). | |
should.equal "foo" => ["bar"] | |
Rack::Utils.parse_query("foo[]=bar&foo[]=baz"). | |
should.equal "foo" => ["bar", "baz"] | |
Rack::Utils.parse_query("foo=bar&baz[]=1&baz[]=2&baz[]=3"). | |
should.equal "foo" => "bar", "baz" => ["1", "2", "3"] | |
Rack::Utils.parse_query("foo[]=bar&baz[]=1&baz[]=2&baz[]=3"). | |
should.equal "foo" => ["bar"], "baz" => ["1", "2", "3"] | |
Rack::Utils.parse_query("foo[bar]=1&foo[]=1").should.raise TypeError |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment