diff options
Diffstat (limited to 'actionpack/test/dispatch/routing_test.rb')
-rw-r--r-- | actionpack/test/dispatch/routing_test.rb | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index d356187ca8..1a8f40037f 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -2324,6 +2324,55 @@ class TestNamespaceWithControllerOption < ActionDispatch::IntegrationTest end end +class TestDrawExternalFile < ActionDispatch::IntegrationTest + class ExternalController < ActionController::Base + def index + render :text => "external#index" + end + end + + DRAW_PATH = Pathname.new(File.expand_path('../../fixtures/routes', __FILE__)) + + DefaultScopeRoutes = ActionDispatch::Routing::RouteSet.new.tap do |app| + app.draw_paths << DRAW_PATH + end + + def app + DefaultScopeRoutes + end + + def test_draw_external_file + DefaultScopeRoutes.draw do + scope :module => 'test_draw_external_file' do + draw :external + end + end + + get '/external' + assert_equal "external#index", @response.body + end + + def test_draw_nonexistent_file + exception = assert_raise ArgumentError do + DefaultScopeRoutes.draw do + draw :nonexistent + end + end + assert_match 'Your router tried to #draw the external file nonexistent.rb', exception.message + assert_match DRAW_PATH.to_s, exception.message + end + + def test_draw_bogus_file + exception = assert_raise NoMethodError do + DefaultScopeRoutes.draw do + draw :bogus + end + end + assert_match "undefined method `wrong'", exception.message + assert_match 'test/fixtures/routes/bogus.rb:1', exception.backtrace.first + end +end + class TestDefaultScope < ActionDispatch::IntegrationTest module ::Blog class PostsController < ActionController::Base @@ -2571,3 +2620,80 @@ class TestOptimizedNamedRoutes < ActionDispatch::IntegrationTest assert_equal '/foo', foo_path end end + +class TestNamedRouteUrlHelpers < ActionDispatch::IntegrationTest + class CategoriesController < ActionController::Base + def show + render :text => "categories#show" + end + end + + class ProductsController < ActionController::Base + def show + render :text => "products#show" + end + end + + Routes = ActionDispatch::Routing::RouteSet.new.tap do |app| + app.draw do + scope :module => "test_named_route_url_helpers" do + get "/categories/:id" => 'categories#show', :as => :category + get "/products/:id" => 'products#show', :as => :product + end + end + end + + def app; Routes end + + include Routes.url_helpers + + test "url helpers do not ignore nil parameters when using non-optimized routes" do + Routes.stubs(:optimize_routes_generation?).returns(false) + + get "/categories/1" + assert_response :success + assert_raises(ActionController::RoutingError) { product_path(nil) } + end +end + +class TestUrlConstraints < ActionDispatch::IntegrationTest + Routes = ActionDispatch::Routing::RouteSet.new.tap do |app| + app.draw do + ok = lambda { |env| [200, { 'Content-Type' => 'text/plain' }, []] } + + constraints :subdomain => 'admin' do + get '/' => ok, :as => :admin_root + end + + scope :constraints => { :protocol => 'https://' } do + get '/' => ok, :as => :secure_root + end + + get '/' => ok, :as => :alternate_root, :constraints => { :port => 8080 } + end + end + + include Routes.url_helpers + def app; Routes end + + test "constraints are copied to defaults when using constraints method" do + assert_equal 'http://admin.example.com/', admin_root_url + + get 'http://admin.example.com/' + assert_response :success + end + + test "constraints are copied to defaults when using scope constraints hash" do + assert_equal 'https://www.example.com/', secure_root_url + + get 'https://www.example.com/' + assert_response :success + end + + test "constraints are copied to defaults when using route constraints hash" do + assert_equal 'http://www.example.com:8080/', alternate_root_url + + get 'http://www.example.com:8080/' + assert_response :success + end +end |