test/routing_test.rb in sinatra-sinatra-0.8.9 vs test/routing_test.rb in sinatra-sinatra-0.8.10
- old
+ new
@@ -25,24 +25,24 @@
end
it "exposes params with indifferent hash" do
mock_app {
get '/:foo' do
- fail unless params['foo'] == 'bar'
- fail unless params[:foo] == 'bar'
+ assert_equal 'bar', params['foo']
+ assert_equal 'bar', params[:foo]
'well, alright'
end
}
get '/bar'
assert_equal 'well, alright', body
end
it "merges named params and query string params in params" do
mock_app {
get '/:foo' do
- fail unless params['foo'] == 'bar'
- fail unless params['baz'] == 'biz'
+ assert_equal 'bar', params['foo']
+ assert_equal 'biz', params['baz']
end
}
get '/bar?baz=biz'
assert ok?
end
@@ -78,11 +78,11 @@
end
it "supports single splat params like /*" do
mock_app {
get '/*' do
- fail unless params['splat'].kind_of?(Array)
+ assert params['splat'].kind_of?(Array)
params['splat'].join "\n"
end
}
get '/foo'
@@ -93,11 +93,11 @@
end
it "supports mixing multiple splat params like /*/foo/*/*" do
mock_app {
get '/*/foo/*/*' do
- fail unless params['splat'].kind_of?(Array)
+ assert params['splat'].kind_of?(Array)
params['splat'].join "\n"
end
}
get '/bar/foo/bling/baz/boom'
@@ -108,19 +108,76 @@
end
it "supports mixing named and splat params like /:foo/*" do
mock_app {
get '/:foo/*' do
- fail unless params['foo'] == 'foo'
- fail unless params['splat'] == ['bar/baz']
+ assert_equal 'foo', params['foo']
+ assert_equal ['bar/baz'], params['splat']
end
}
get '/foo/bar/baz'
assert ok?
end
+ it "supports basic nested params" do
+ mock_app {
+ get '/hi' do
+ params["person"]["name"]
+ end
+ }
+
+ get "/hi?person[name]=John+Doe"
+ assert ok?
+ assert_equal "John Doe", body
+ end
+
+ it "exposes nested params with indifferent hash" do
+ mock_app {
+ get '/testme' do
+ assert_equal 'baz', params['bar']['foo']
+ assert_equal 'baz', params['bar'][:foo]
+ 'well, alright'
+ end
+ }
+ get '/testme?bar[foo]=baz'
+ assert_equal 'well, alright', body
+ end
+
+ it "supports deeply nested params" do
+ input = {
+ 'browser[chrome][engine][name]' => 'V8',
+ 'browser[chrome][engine][version]' => '1.0',
+ 'browser[firefox][engine][name]' => 'spidermonkey',
+ 'browser[firefox][engine][version]' => '1.7.0',
+ 'emacs[map][goto-line]' => 'M-g g',
+ 'emacs[version]' => '22.3.1',
+ 'paste[name]' => 'hello world',
+ 'paste[syntax]' => 'ruby'
+ }
+ expected = {
+ "emacs" => {
+ "map" => { "goto-line" => "M-g g" },
+ "version" => "22.3.1"
+ },
+ "browser" => {
+ "firefox" => {"engine" => {"name"=>"spidermonkey", "version"=>"1.7.0"}},
+ "chrome" => {"engine" => {"name"=>"V8", "version"=>"1.0"}}
+ },
+ "paste" => {"name"=>"hello world", "syntax"=>"ruby"}
+ }
+ mock_app {
+ get '/foo' do
+ assert_equal expected, params
+ 'looks good'
+ end
+ }
+ get "/foo?#{param_string(input)}"
+ assert ok?
+ assert_equal 'looks good', body
+ end
+
it "supports paths that include spaces" do
mock_app {
get '/path with spaces' do
'looks good'
end
@@ -132,12 +189,12 @@
end
it "URL decodes named parameters and splats" do
mock_app {
get '/:foo/*' do
- fail unless params['foo'] == 'hello world'
- fail unless params['splat'] == ['how are you']
+ assert_equal 'hello world', params['foo']
+ assert_equal ['how are you'], params['splat']
nil
end
}
get '/hello%20world/how%20are%20you'
@@ -157,11 +214,11 @@
end
it 'makes regular expression captures available in params[:captures]' do
mock_app {
get(/^\/fo(.*)\/ba(.*)/) do
- fail unless params[:captures] == ['orooomma', 'f']
+ assert_equal ['orooomma', 'f'], params[:captures]
'right on'
end
}
get '/foorooomma/baf'
@@ -188,10 +245,10 @@
pass
'Hello Foo'
end
get '/*' do
- fail if params.include?('foo')
+ assert !params.include?('foo')
'Hello World'
end
}
get '/bar'