diff options
author | Piotr Sarnacki <drogus@gmail.com> | 2010-07-07 11:26:03 +0200 |
---|---|---|
committer | Piotr Sarnacki <drogus@gmail.com> | 2010-09-03 22:59:05 +0200 |
commit | 451c9942bb493190d5673c1b55be7506056db13b (patch) | |
tree | 4570ad54ce7d5c9ff2cab6ab3697531ec903b7ca /actionpack/test | |
parent | 628b94fbc81cb02b753d0f717a875219853b5764 (diff) | |
download | rails-451c9942bb493190d5673c1b55be7506056db13b.tar.gz rails-451c9942bb493190d5673c1b55be7506056db13b.tar.bz2 rails-451c9942bb493190d5673c1b55be7506056db13b.zip |
Allow to generate Application routes inside Engine
This requires knowledge about original SCRIPT_NAME and
the parent router. It should be pass through the env
as ORIGIAL_SCRIPT_NAME and action_dispatch.parent_routes
Diffstat (limited to 'actionpack/test')
-rw-r--r-- | actionpack/test/dispatch/prefix_generation_test.rb | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/actionpack/test/dispatch/prefix_generation_test.rb b/actionpack/test/dispatch/prefix_generation_test.rb index 95d5c1c366..efc56c067b 100644 --- a/actionpack/test/dispatch/prefix_generation_test.rb +++ b/actionpack/test/dispatch/prefix_generation_test.rb @@ -8,6 +8,7 @@ module TestGenerationPrefix routes = ActionDispatch::Routing::RouteSet.new routes.draw do match "/posts/:id", :to => "inside_engine_generating#index", :as => :post + match "/bare_url_for", :to => "inside_engine_generating#bare_url_for", :as => :bare_url_for end routes @@ -37,6 +38,10 @@ module TestGenerationPrefix def self.call(env) env['action_dispatch.routes'] = routes + + # the next to values should be set only in application + env['ORIGINAL_SCRIPT_NAME'] = env['SCRIPT_NAME'] + env['action_dispatch.parent_routes'] = routes routes.call(env) end end @@ -46,6 +51,14 @@ module TestGenerationPrefix def index render :text => post_path(:id => params[:id]) end + + def bare_url_for + path = url_for( :routes => RailsApplication.routes, + :controller => "outside_engine_generating", + :action => "index", + :only_path => true) + render :text => path + end end class ::OutsideEngineGeneratingController < ActionController::Base @@ -73,9 +86,8 @@ module TestGenerationPrefix end test "use SCRIPT_NAME inside the engine" do - env = Rack::MockRequest.env_for("/posts/1") - env["SCRIPT_NAME"] = "/pure-awesomness/blog" - response = ActionDispatch::Response.new(*BlogEngine.call(env)) + env = Rack::MockRequest.env_for("/pure-awesomness/blog/posts/1") + response = ActionDispatch::Response.new(*RailsApplication.call(env)) assert_equal "/pure-awesomness/blog/posts/1", response.body end @@ -98,5 +110,12 @@ module TestGenerationPrefix test "generating urls from a regular class" do assert_equal "/awesome/blog/posts/42", Foo.new.foo end + + test "passing :routes to url_for to change current routes" do + env = Rack::MockRequest.env_for("/pure-awesomness/blog/bare_url_for") + env["SCRIPT_NAME"] = "/something" + response = ActionDispatch::Response.new(*RailsApplication.call(env)) + assert_equal "/something/generate", response.body + end end end |