Permalink
Browse files

Include routes.mounted_helpers into integration tests

In integration tests, you might want to use helpers from engines that
you mounted in your application. It's not hard to add it by yourself,
but it's unneeded boilerplate. mounted_helpers are now included by
default. That means that given engine mounted like:

    mount Foo::Engine => "/foo", :as => "foo"

you will be able to use paths from this engine in tests this way:

    foo.root_path #=> "/foo"

(closes #6573)
  • Loading branch information...
1 parent ecd1722 commit 8d4f63a1a593928c1718e73043c8ca525440fb6b @drogus drogus committed Jun 1, 2012
View
@@ -1,3 +1,7 @@
+## Rails 3.2.6 (unreleased) ##
+
+* Include mounted_helpers (helpers for accessing mounted engines) in ActionDispatch::IntegrationTest by default. *Piotr Sarnacki*
+
## Rails 3.2.4 (May 31, 2012) ##
* Deprecate old APIs for highlight, excerpt and word_wrap *Jeremy Walker*
@@ -177,8 +177,11 @@ def initialize(app)
# If the app is a Rails app, make url_helpers available on the session
# This makes app.url_for and app.foo_path available in the console
- if app.respond_to?(:routes) && app.routes.respond_to?(:url_helpers)
- singleton_class.class_eval { include app.routes.url_helpers }
+ if app.respond_to?(:routes)
+ singleton_class.class_eval do
+ include app.routes.url_helpers if app.routes.respond_to?(:url_helpers)
+ include app.routes.mounted_helpers if app.routes.respond_to?(:mounted_helpers)
+ end
end
reset!
@@ -495,11 +495,26 @@ def self.routes
@routes ||= ActionDispatch::Routing::RouteSet.new
end
+ class MountedApp
+ def self.routes
+ @routes ||= ActionDispatch::Routing::RouteSet.new
+ end
+
+ routes.draw do
+ match 'baz', :to => 'application_integration_test/test#index', :as => :baz
+ end
+
+ def self.call(*)
+ end
+ end
+
routes.draw do
match '', :to => 'application_integration_test/test#index', :as => :empty_string
match 'foo', :to => 'application_integration_test/test#index', :as => :foo
match 'bar', :to => 'application_integration_test/test#index', :as => :bar
+
+ mount MountedApp => '/mounted', :as => "mounted"
end
def app
@@ -512,6 +527,10 @@ def app
assert_equal '/bar', bar_path
end
+ test "includes mounted helpers" do
+ assert_equal '/mounted/baz', mounted.baz_path
+ end
+
test "route helpers after controller access" do
get '/'
assert_equal '/', empty_string_path

0 comments on commit 8d4f63a

Please sign in to comment.