From 23b6def0eb76ac0719e420fce91ba862f880a37b Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Tue, 16 Mar 2010 14:55:42 -0700 Subject: Do not always include the named URL helpers into AC::Base and AV::Base. --- .../lib/action_dispatch/testing/assertions/routing.rb | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'actionpack/lib/action_dispatch/testing/assertions/routing.rb') diff --git a/actionpack/lib/action_dispatch/testing/assertions/routing.rb b/actionpack/lib/action_dispatch/testing/assertions/routing.rb index 1d7e8090e4..eb28cd5107 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/routing.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/routing.rb @@ -145,11 +145,25 @@ module ActionDispatch old_routes, @router = @router, ActionDispatch::Routing::RouteSet.new old_controller, @controller = @controller, @controller.clone if @controller _router = @router - @controller.singleton_class.send(:send, :include, @router.url_helpers) if @controller + + # Unfortunately, there is currently an abstraction leak between AC::Base + # and AV::Base which requires having the URL helpers in both AC and AV. + # To do this safely at runtime for tests, we need to bump up the helper serial + # to that the old AV subclass isn't cached. + # + # TODO: Make this unnecessary + if @controller + @controller.singleton_class.send(:include, @router.url_helpers) + @controller.class._helper_serial += 1 + @controller.view_context.singleton_class.send(:include, @router.url_helpers) + end yield @router ensure @router = old_routes - @controller = old_controller if @controller + if @controller + @controller = old_controller + @controller.class._helper_serial += 1 if @controller + end end # ROUTES TODO: These assertions should really work in an integration context -- cgit v1.2.3 From 71c9337f45f9c5461cbc6ddf6cab764ad0f82c3b Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Thu, 18 Mar 2010 15:52:43 -0700 Subject: All tests pass without memoizing view_context --- actionpack/lib/action_dispatch/testing/assertions/routing.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'actionpack/lib/action_dispatch/testing/assertions/routing.rb') diff --git a/actionpack/lib/action_dispatch/testing/assertions/routing.rb b/actionpack/lib/action_dispatch/testing/assertions/routing.rb index eb28cd5107..de833bb3ca 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/routing.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/routing.rb @@ -154,15 +154,14 @@ module ActionDispatch # TODO: Make this unnecessary if @controller @controller.singleton_class.send(:include, @router.url_helpers) - @controller.class._helper_serial += 1 - @controller.view_context.singleton_class.send(:include, @router.url_helpers) + @controller.class._helper_serial = AbstractController::Helpers.next_serial + 1 end yield @router ensure @router = old_routes if @controller @controller = old_controller - @controller.class._helper_serial += 1 if @controller + @controller.class._helper_serial = AbstractController::Helpers.next_serial + 1 if @controller end end -- cgit v1.2.3 From a5d80f84d269bba6b0f0802612f29df1ee09d720 Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Thu, 18 Mar 2010 18:12:04 -0700 Subject: Each controller class has it's own view context subclass. This removes the need for ActionView::Base.for_controller --- actionpack/lib/action_dispatch/testing/assertions/routing.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'actionpack/lib/action_dispatch/testing/assertions/routing.rb') diff --git a/actionpack/lib/action_dispatch/testing/assertions/routing.rb b/actionpack/lib/action_dispatch/testing/assertions/routing.rb index de833bb3ca..1bb81ede3b 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/routing.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/routing.rb @@ -153,15 +153,16 @@ module ActionDispatch # # TODO: Make this unnecessary if @controller - @controller.singleton_class.send(:include, @router.url_helpers) - @controller.class._helper_serial = AbstractController::Helpers.next_serial + 1 + @controller.singleton_class.send(:include, _router.url_helpers) + @controller.view_context_class = Class.new(@controller.view_context_class) do + include _router.url_helpers + end end yield @router ensure @router = old_routes if @controller @controller = old_controller - @controller.class._helper_serial = AbstractController::Helpers.next_serial + 1 if @controller end end -- cgit v1.2.3