From 17f0c1e9e8a5bfa7c4d2e1632c3b8b91f4678f03 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 30 Mar 2010 13:58:18 -0500 Subject: Fix stack overflow bug in integration test router helpers --- .../action_dispatch/testing/assertions/routing.rb | 2 +- actionpack/test/controller/integration_test.rb | 47 ++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/testing/assertions/routing.rb b/actionpack/lib/action_dispatch/testing/assertions/routing.rb index 1bb81ede3b..08f3d90e18 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/routing.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/routing.rb @@ -168,7 +168,7 @@ module ActionDispatch # ROUTES TODO: These assertions should really work in an integration context def method_missing(selector, *args, &block) - if @controller && @router.named_routes.helpers.include?(selector) + if @controller && @router && @router.named_routes.helpers.include?(selector) @controller.send(selector, *args, &block) else super diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb index c9782856bd..1e2ee06adc 100644 --- a/actionpack/test/controller/integration_test.rb +++ b/actionpack/test/controller/integration_test.rb @@ -430,3 +430,50 @@ class MetalIntegrationTest < ActionController::IntegrationTest assert_equal 'http://www.example.com/foo', url_for(:controller => "foo") end end + +class ApplicationIntegrationTest < ActionController::IntegrationTest + class TestController < ActionController::Base + def index + render :text => "index" + end + end + + def self.call(env) + routes.call(env) + end + + def self.routes + @routes ||= ActionDispatch::Routing::RouteSet.new + end + + routes.draw do + match 'foo', :to => 'application_integration_test/test#index', :as => :foo + match 'bar', :to => 'application_integration_test/test#index', :as => :bar + end + + def app + self.class + end + + test "includes route helpers" do + assert_equal '/foo', foo_path + assert_equal '/bar', bar_path + end + + test "route helpers after controller access" do + get '/foo' + assert_equal '/foo', foo_path + + get '/bar' + assert_equal '/bar', bar_path + end + + test "missing route helper before controller access" do + assert_raise(NameError) { missing_path } + end + + test "missing route helper after controller access" do + get '/foo' + assert_raise(NameError) { missing_path } + end +end -- cgit v1.2.3