aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/dispatch/prefix_generation_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/test/dispatch/prefix_generation_test.rb')
-rw-r--r--actionpack/test/dispatch/prefix_generation_test.rb84
1 files changed, 70 insertions, 14 deletions
diff --git a/actionpack/test/dispatch/prefix_generation_test.rb b/actionpack/test/dispatch/prefix_generation_test.rb
index 2eb592c8d0..7fe11447b8 100644
--- a/actionpack/test/dispatch/prefix_generation_test.rb
+++ b/actionpack/test/dispatch/prefix_generation_test.rb
@@ -13,6 +13,7 @@ module TestGenerationPrefix
match "/posts/:id", :to => "inside_engine_generating#show", :as => :post
match "/posts", :to => "inside_engine_generating#index", :as => :posts
match "/url_to_application", :to => "inside_engine_generating#url_to_application"
+ match "/polymorphic_path_for_engine", :to => "inside_engine_generating#polymorphic_path_for_engine"
end
routes
@@ -31,9 +32,11 @@ module TestGenerationPrefix
routes = ActionDispatch::Routing::RouteSet.new
routes.draw do
scope "/:omg", :omg => "awesome" do
- mount BlogEngine => "/blog"
+ mount BlogEngine => "/blog", :as => "blog_engine"
end
match "/generate", :to => "outside_engine_generating#index"
+ match "/polymorphic_path_for_engine", :to => "outside_engine_generating#polymorphic_path_for_engine"
+ match "/polymorphic_with_url_for", :to => "outside_engine_generating#polymorphic_with_url_for"
root :to => "outside_engine_generating#index"
end
@@ -47,8 +50,27 @@ module TestGenerationPrefix
end
end
+ # force draw
+ RailsApplication.routes
+
+ class Post
+ extend ActiveModel::Naming
+
+ def to_param
+ "1"
+ end
+
+ def self.model_name
+ klass = "Post"
+ def klass.name; self end
+
+ ActiveModel::Name.new(klass)
+ end
+ end
+
class ::InsideEngineGeneratingController < ActionController::Base
include BlogEngine.routes.url_helpers
+ include RailsApplication.routes.mounted_helpers(:app)
def index
render :text => posts_path
@@ -59,17 +81,30 @@ module TestGenerationPrefix
end
def url_to_application
- path = url_for( RailsApplication,
- :controller => "outside_engine_generating",
- :action => "index",
- :only_path => true)
+ path = app.url_for( :controller => "outside_engine_generating",
+ :action => "index",
+ :only_path => true)
render :text => path
end
+
+ def polymorphic_path_for_engine
+ render :text => polymorphic_path(Post.new)
+ end
end
class ::OutsideEngineGeneratingController < ActionController::Base
+ include BlogEngine.routes.mounted_helpers
+
def index
- render :text => url_for(BlogEngine, :post_path, :id => 1)
+ render :text => blog_engine.post_path(:id => 1)
+ end
+
+ def polymorphic_path_for_engine
+ render :text => blog_engine.polymorphic_path(Post.new)
+ end
+
+ def polymorphic_with_url_for
+ render :text => blog_engine.url_for(Post.new)
end
end
@@ -83,9 +118,6 @@ module TestGenerationPrefix
include RailsApplication.routes.url_helpers
end
- # force draw
- RailsApplication.routes
-
def app
RailsApplication
end
@@ -124,7 +156,12 @@ module TestGenerationPrefix
get "/pure-awesomeness/blog/url_to_application", {}, 'SCRIPT_NAME' => '/foo'
assert_equal "/something/generate", last_response.body
end
-
+
+ test "[ENGINE] generating engine's url with polymorphic path" do
+ get "/pure-awesomeness/blog/polymorphic_path_for_engine"
+ assert_equal "/pure-awesomeness/blog/posts/1", last_response.body
+ end
+
# Inside Application
test "[APP] generating engine's route includes prefix" do
get "/generate"
@@ -143,6 +180,16 @@ module TestGenerationPrefix
assert_equal "/something/awesome/blog/posts/1", last_response.body
end
+ test "[APP] generating engine's url with polymorphic path" do
+ get "/polymorphic_path_for_engine"
+ assert_equal "/awesome/blog/posts/1", last_response.body
+ end
+
+ test "[APP] generating engine's url with url_for(@post)" do
+ get "/polymorphic_with_url_for"
+ assert_equal "http://example.org/awesome/blog/posts/1", last_response.body
+ end
+
# Inside any Object
test "[OBJECT] generating engine's route includes prefix" do
assert_equal "/awesome/blog/posts/1", engine_object.post_path(:id => 1)
@@ -167,19 +214,28 @@ module TestGenerationPrefix
end
test "[OBJECT] generating engine's route with url_for" do
- path = engine_object.url_for(BlogEngine,
- :controller => "inside_engine_generating",
+ path = engine_object.url_for(:controller => "inside_engine_generating",
:action => "show",
:only_path => true,
:omg => "omg",
:id => 1)
assert_equal "/omg/blog/posts/1", path
+ end
- path = engine_object.url_for(BlogEngine, :posts_path)
+ test "[OBJECT] generating engine's route with named helpers" do
+ path = engine_object.posts_path
assert_equal "/awesome/blog/posts", path
- path = engine_object.url_for(BlogEngine, :posts_url, :host => "example.com")
+ path = engine_object.posts_url(:host => "example.com")
assert_equal "http://example.com/awesome/blog/posts", path
end
+
+ test "[OBJECT] generating engine's route with polymorphic_url" do
+ path = engine_object.polymorphic_path(Post.new)
+ assert_equal "/awesome/blog/posts/1", path
+
+ path = engine_object.polymorphic_url(Post.new, :host => "www.example.com")
+ assert_equal "http://www.example.com/awesome/blog/posts/1", path
+ end
end
end