test/unit/router_tests.rb in deas-0.42.0 vs test/unit/router_tests.rb in deas-0.43.0
- old
+ new
@@ -41,11 +41,11 @@
should have_imeths :request_type_name
should have_imeths :get, :post, :put, :patch, :delete
should have_imeths :route, :redirect, :not_found
should have_imeths :apply_definitions!, :validate!
- should "default its settings" do
+ should "default its attrs" do
router = @router_class.new
assert_nil router.view_handler_ns
assert_nil router.base_url
assert_empty router.request_types
assert_empty router.urls
@@ -368,15 +368,44 @@
proxy = route.handler_proxies[subject.default_request_type_name]
handler = test_handler(proxy.handler_class)
assert_equal [404, {}, body], handler.halt_args
end
+ should "complain if adding a route with invalid splats in its path" do
+ [ "/something/other*/",
+ "/something/other*",
+ "/something/*other",
+ "/something*/other",
+ "/*something/other",
+ "/something/*/other/*",
+ "/something/*/other",
+ "/something/*/",
+ "/*/something",
+ ].each do |path|
+ assert_raises InvalidSplatError do
+ router = @router_class.new
+ router.route(:get, path)
+ router.apply_definitions!
+ end
+ end
+
+ [ "/something/*",
+ "/*"
+ ].each do |path|
+ assert_nothing_raised do
+ router = @router_class.new
+ router.route(:get, path)
+ router.apply_definitions!
+ end
+ end
+ end
+
end
class NamedUrlTests < InitTests
setup do
- @router.url('get_info', '/info/:for')
+ @router.url(:get_info, '/info/:for')
end
should "define a url given a name and a path" do
url = subject.urls[:get_info]
@@ -386,43 +415,28 @@
assert_equal '/info/:for', url.path
assert_equal subject.escape_query_value_proc, url.escape_query_value_proc
end
should "define a url with a custom escape query value proc" do
- name = Factory.string
+ name = Factory.string.to_sym
escape_proc = proc{ Factory.string }
@router.url(name, Factory.path, :escape_query_value => escape_proc)
- url = subject.urls[name.to_sym]
+ url = subject.urls[name]
assert_equal escape_proc, url.escape_query_value_proc
end
- should "complain if defining a url with a non-string path" do
+ should "complain if defining a url with a non-symbol name" do
assert_raises ArgumentError do
- subject.url(:get_info, /^\/info/)
+ subject.url('get_info', '/info')
end
end
- should "complain if defining a url with invalid splats" do
+ should "complain if defining a url with a non-string path" do
assert_raises ArgumentError do
- subject.url(:get_info, "/something/*/other/*")
+ subject.url(:get_info, /^\/info/)
end
- assert_raises ArgumentError do
- subject.url(:get_info, "/something/*/other")
- end
- assert_raises ArgumentError do
- subject.url(:get_info, "/something/*/")
- end
- assert_raises ArgumentError do
- subject.url(:get_info, "/*/something")
- end
- assert_nothing_raised do
- subject.url(:get_info, "/something/*")
- end
- assert_nothing_raised do
- subject.url(:get_info, "/*")
- end
end
should "build a path for a url given params" do
exp_path = subject.prepend_base_url("/info/now")
assert_equal exp_path, subject.url_for(:get_info, :for => 'now')
@@ -508,10 +522,10 @@
should "prepend the base url when building named urls" do
url = Factory.url
subject.base_url url
path = Factory.path
- subject.url('base_get_info', path)
+ subject.url(:base_get_info, path)
exp_path = subject.prepend_base_url(path)
assert_equal exp_path, subject.url_for(:base_get_info)
end