test/unit/router_tests.rb in deas-0.25.0 vs test/unit/router_tests.rb in deas-0.26.0
- old
+ new
@@ -9,11 +9,11 @@
@router = Deas::Router.new
end
subject{ @router }
should have_accessors :urls, :routes
- should have_imeths :view_handler_ns, :base_url
+ should have_imeths :view_handler_ns, :base_url, :prepend_base_url
should have_imeths :url, :url_for
should have_imeths :get, :post, :put, :patch, :delete
should have_imeths :route, :redirect
should "have no view_handler_ns, base_url, urls, or routes by default" do
@@ -101,16 +101,27 @@
subject.base_url url
assert_equal url, subject.base_url
end
- should "use the base url when adding routes" do
+ should "prepend the base url to any url path" do
+ url_path = Factory.path
+ base_url = Factory.url
+
+ assert_equal url_path, subject.prepend_base_url(url_path)
+
+ subject.base_url base_url
+ assert_equal "#{base_url}#{url_path}", subject.prepend_base_url(url_path)
+ end
+
+ should "prepend the base url when adding routes" do
url = Factory.url
subject.base_url url
- route = subject.get('/some-path', Object)
+ path = Factory.path
+ route = subject.get(path, Object)
- exp_path = "#{url}/some-path"
+ exp_path = subject.prepend_base_url(path)
assert_equal exp_path, route.path
end
should "add a redirect route using #redirect" do
subject.redirect('/invalid', '/assets')
@@ -195,16 +206,17 @@
route = subject.routes.last
assert_equal url.path, route.path
end
- should "use the base url when building named urls" do
+ should "prepend the base url when building named urls" do
url = Factory.url
subject.base_url url
- subject.url('base_get_info', '/info/:for')
+ path = Factory.path
+ subject.url('base_get_info', path)
- exp_path = "#{url}/info/now"
- assert_equal exp_path, subject.url_for(:base_get_info, :for => 'now')
+ exp_path = subject.prepend_base_url(path)
+ assert_equal exp_path, subject.url_for(:base_get_info)
end
end
end