2010-07-01 03:04:30 -04:00
|
|
|
require 'abstract_unit'
|
2010-09-25 13:22:32 -04:00
|
|
|
require 'rack/test'
|
2014-07-16 18:41:47 -04:00
|
|
|
require 'rails/engine'
|
2010-07-01 03:04:30 -04:00
|
|
|
|
|
|
|
module TestGenerationPrefix
|
2010-09-25 13:22:32 -04:00
|
|
|
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
|
2014-05-12 13:26:20 -04:00
|
|
|
|
|
|
|
def to_model; self; end
|
|
|
|
def persisted?; true; end
|
2010-09-25 13:22:32 -04:00
|
|
|
end
|
|
|
|
|
2010-07-01 03:04:30 -04:00
|
|
|
class WithMountedEngine < ActionDispatch::IntegrationTest
|
2010-07-08 17:27:49 -04:00
|
|
|
include Rack::Test::Methods
|
|
|
|
|
2014-07-16 18:41:47 -04:00
|
|
|
class BlogEngine < Rails::Engine
|
2014-08-05 19:50:50 -04:00
|
|
|
routes.draw do
|
|
|
|
get "/posts/:id", :to => "inside_engine_generating#show", :as => :post
|
|
|
|
get "/posts", :to => "inside_engine_generating#index", :as => :posts
|
|
|
|
get "/url_to_application", :to => "inside_engine_generating#url_to_application"
|
|
|
|
get "/polymorphic_path_for_engine", :to => "inside_engine_generating#polymorphic_path_for_engine"
|
|
|
|
get "/conflicting_url", :to => "inside_engine_generating#conflicting"
|
|
|
|
get "/foo", :to => "never#invoked", :as => :named_helper_that_should_be_invoked_only_in_respond_to_test
|
|
|
|
|
|
|
|
get "/relative_path_root", :to => redirect("")
|
|
|
|
get "/relative_path_redirect", :to => redirect("foo")
|
|
|
|
get "/relative_option_root", :to => redirect(:path => "")
|
|
|
|
get "/relative_option_redirect", :to => redirect(:path => "foo")
|
|
|
|
get "/relative_custom_root", :to => redirect { |params, request| "" }
|
|
|
|
get "/relative_custom_redirect", :to => redirect { |params, request| "foo" }
|
|
|
|
|
|
|
|
get "/absolute_path_root", :to => redirect("/")
|
|
|
|
get "/absolute_path_redirect", :to => redirect("/foo")
|
|
|
|
get "/absolute_option_root", :to => redirect(:path => "/")
|
|
|
|
get "/absolute_option_redirect", :to => redirect(:path => "/foo")
|
|
|
|
get "/absolute_custom_root", :to => redirect { |params, request| "/" }
|
|
|
|
get "/absolute_custom_redirect", :to => redirect { |params, request| "/foo" }
|
2010-07-01 03:04:30 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-08-05 19:30:08 -04:00
|
|
|
class RailsApplication < Rails::Engine
|
2014-08-05 19:50:50 -04:00
|
|
|
routes.draw do
|
|
|
|
scope "/:omg", :omg => "awesome" do
|
|
|
|
mount BlogEngine => "/blog", :as => "blog_engine"
|
2010-07-01 03:04:30 -04:00
|
|
|
end
|
2014-08-05 19:50:50 -04:00
|
|
|
get "/posts/:id", :to => "outside_engine_generating#post", :as => :post
|
|
|
|
get "/generate", :to => "outside_engine_generating#index"
|
|
|
|
get "/polymorphic_path_for_app", :to => "outside_engine_generating#polymorphic_path_for_app"
|
|
|
|
get "/polymorphic_path_for_engine", :to => "outside_engine_generating#polymorphic_path_for_engine"
|
|
|
|
get "/polymorphic_with_url_for", :to => "outside_engine_generating#polymorphic_with_url_for"
|
|
|
|
get "/conflicting_url", :to => "outside_engine_generating#conflicting"
|
|
|
|
get "/ivar_usage", :to => "outside_engine_generating#ivar_usage"
|
|
|
|
root :to => "outside_engine_generating#index"
|
2010-07-01 03:04:30 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-07-18 13:49:51 -04:00
|
|
|
# force draw
|
2011-04-25 11:57:41 -04:00
|
|
|
RailsApplication.routes.define_mounted_helper(:main_app)
|
2010-07-18 13:49:51 -04:00
|
|
|
|
2010-07-01 03:04:30 -04:00
|
|
|
class ::InsideEngineGeneratingController < ActionController::Base
|
2010-07-14 19:18:02 -04:00
|
|
|
include BlogEngine.routes.url_helpers
|
2010-09-06 14:47:25 -04:00
|
|
|
include RailsApplication.routes.mounted_helpers
|
2010-07-14 19:18:02 -04:00
|
|
|
|
2010-07-01 03:04:30 -04:00
|
|
|
def index
|
2010-07-14 19:18:02 -04:00
|
|
|
render :text => posts_path
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
render :text => post_path(:id => params[:id])
|
2010-07-01 03:04:30 -04:00
|
|
|
end
|
2010-07-07 05:26:03 -04:00
|
|
|
|
2010-07-09 04:25:10 -04:00
|
|
|
def url_to_application
|
2010-09-07 08:53:37 -04:00
|
|
|
path = main_app.url_for(:controller => "outside_engine_generating",
|
|
|
|
:action => "index",
|
|
|
|
:only_path => true)
|
2010-07-07 05:26:03 -04:00
|
|
|
render :text => path
|
|
|
|
end
|
2010-07-18 13:49:51 -04:00
|
|
|
|
|
|
|
def polymorphic_path_for_engine
|
|
|
|
render :text => polymorphic_path(Post.new)
|
|
|
|
end
|
2010-07-19 07:32:34 -04:00
|
|
|
|
|
|
|
def conflicting
|
|
|
|
render :text => "engine"
|
|
|
|
end
|
2010-07-01 03:04:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
class ::OutsideEngineGeneratingController < ActionController::Base
|
2010-07-18 13:49:51 -04:00
|
|
|
include BlogEngine.routes.mounted_helpers
|
2011-06-06 08:13:06 -04:00
|
|
|
include RailsApplication.routes.url_helpers
|
2010-07-18 13:49:51 -04:00
|
|
|
|
2010-07-01 03:04:30 -04:00
|
|
|
def index
|
2010-07-18 13:49:51 -04:00
|
|
|
render :text => blog_engine.post_path(:id => 1)
|
|
|
|
end
|
|
|
|
|
|
|
|
def polymorphic_path_for_engine
|
|
|
|
render :text => blog_engine.polymorphic_path(Post.new)
|
|
|
|
end
|
|
|
|
|
2011-06-06 08:13:06 -04:00
|
|
|
def polymorphic_path_for_app
|
|
|
|
render :text => polymorphic_path(Post.new)
|
|
|
|
end
|
|
|
|
|
2010-07-18 13:49:51 -04:00
|
|
|
def polymorphic_with_url_for
|
|
|
|
render :text => blog_engine.url_for(Post.new)
|
2010-07-01 03:04:30 -04:00
|
|
|
end
|
2010-07-19 07:32:34 -04:00
|
|
|
|
|
|
|
def conflicting
|
|
|
|
render :text => "application"
|
|
|
|
end
|
2012-09-09 02:59:21 -04:00
|
|
|
|
|
|
|
def ivar_usage
|
|
|
|
@blog_engine = "Not the engine route helper"
|
|
|
|
render :text => blog_engine.post_path(:id => 1)
|
|
|
|
end
|
2010-07-01 03:04:30 -04:00
|
|
|
end
|
|
|
|
|
2010-07-14 19:18:02 -04:00
|
|
|
class EngineObject
|
2010-07-01 03:04:30 -04:00
|
|
|
include ActionDispatch::Routing::UrlFor
|
|
|
|
include BlogEngine.routes.url_helpers
|
|
|
|
end
|
|
|
|
|
2010-07-14 19:18:02 -04:00
|
|
|
class AppObject
|
2010-07-08 17:27:49 -04:00
|
|
|
include ActionDispatch::Routing::UrlFor
|
|
|
|
include RailsApplication.routes.url_helpers
|
|
|
|
end
|
2010-07-01 03:04:30 -04:00
|
|
|
|
2010-07-08 17:27:49 -04:00
|
|
|
def app
|
2014-08-05 19:50:50 -04:00
|
|
|
RailsApplication.instance
|
2010-07-08 17:27:49 -04:00
|
|
|
end
|
|
|
|
|
2014-08-05 12:45:21 -04:00
|
|
|
attr_reader :engine_object, :app_object
|
2010-07-14 19:18:02 -04:00
|
|
|
|
2010-07-08 17:27:49 -04:00
|
|
|
def setup
|
|
|
|
RailsApplication.routes.default_url_options = {}
|
2014-08-05 12:45:21 -04:00
|
|
|
@engine_object = EngineObject.new
|
|
|
|
@app_object = AppObject.new
|
2010-07-08 17:27:49 -04:00
|
|
|
end
|
|
|
|
|
2012-01-03 14:26:45 -05:00
|
|
|
include BlogEngine.routes.mounted_helpers
|
|
|
|
|
2010-07-14 19:18:02 -04:00
|
|
|
# Inside Engine
|
|
|
|
test "[ENGINE] generating engine's url use SCRIPT_NAME from request" do
|
|
|
|
get "/pure-awesomeness/blog/posts/1"
|
|
|
|
assert_equal "/pure-awesomeness/blog/posts/1", last_response.body
|
2010-07-01 03:04:30 -04:00
|
|
|
end
|
|
|
|
|
2010-07-14 19:18:02 -04:00
|
|
|
test "[ENGINE] generating application's url never uses SCRIPT_NAME from request" do
|
|
|
|
get "/pure-awesomeness/blog/url_to_application"
|
|
|
|
assert_equal "/generate", last_response.body
|
2010-07-01 03:04:30 -04:00
|
|
|
end
|
|
|
|
|
2010-07-18 13:49:51 -04:00
|
|
|
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
|
|
|
|
|
2010-07-19 07:32:34 -04:00
|
|
|
test "[ENGINE] url_helpers from engine have higher priotity than application's url_helpers" do
|
|
|
|
get "/awesome/blog/conflicting_url"
|
|
|
|
assert_equal "engine", last_response.body
|
|
|
|
end
|
|
|
|
|
2014-01-01 06:15:31 -05:00
|
|
|
test "[ENGINE] relative path root uses SCRIPT_NAME from request" do
|
|
|
|
get "/awesome/blog/relative_path_root"
|
|
|
|
verify_redirect "http://example.org/awesome/blog"
|
|
|
|
end
|
|
|
|
|
2013-10-10 08:01:03 -04:00
|
|
|
test "[ENGINE] relative path redirect uses SCRIPT_NAME from request" do
|
|
|
|
get "/awesome/blog/relative_path_redirect"
|
2014-01-01 06:15:31 -05:00
|
|
|
verify_redirect "http://example.org/awesome/blog/foo"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "[ENGINE] relative option root uses SCRIPT_NAME from request" do
|
|
|
|
get "/awesome/blog/relative_option_root"
|
|
|
|
verify_redirect "http://example.org/awesome/blog"
|
2013-10-10 08:01:03 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test "[ENGINE] relative option redirect uses SCRIPT_NAME from request" do
|
|
|
|
get "/awesome/blog/relative_option_redirect"
|
2014-01-01 06:15:31 -05:00
|
|
|
verify_redirect "http://example.org/awesome/blog/foo"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "[ENGINE] relative custom root uses SCRIPT_NAME from request" do
|
|
|
|
get "/awesome/blog/relative_custom_root"
|
|
|
|
verify_redirect "http://example.org/awesome/blog"
|
2013-10-10 08:01:03 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test "[ENGINE] relative custom redirect uses SCRIPT_NAME from request" do
|
|
|
|
get "/awesome/blog/relative_custom_redirect"
|
2014-01-01 06:15:31 -05:00
|
|
|
verify_redirect "http://example.org/awesome/blog/foo"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "[ENGINE] absolute path root doesn't use SCRIPT_NAME from request" do
|
|
|
|
get "/awesome/blog/absolute_path_root"
|
|
|
|
verify_redirect "http://example.org/"
|
2013-10-10 08:01:03 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test "[ENGINE] absolute path redirect doesn't use SCRIPT_NAME from request" do
|
|
|
|
get "/awesome/blog/absolute_path_redirect"
|
2014-01-01 06:15:31 -05:00
|
|
|
verify_redirect "http://example.org/foo"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "[ENGINE] absolute option root doesn't use SCRIPT_NAME from request" do
|
|
|
|
get "/awesome/blog/absolute_option_root"
|
|
|
|
verify_redirect "http://example.org/"
|
2013-10-10 08:01:03 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test "[ENGINE] absolute option redirect doesn't use SCRIPT_NAME from request" do
|
|
|
|
get "/awesome/blog/absolute_option_redirect"
|
2014-01-01 06:15:31 -05:00
|
|
|
verify_redirect "http://example.org/foo"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "[ENGINE] absolute custom root doesn't use SCRIPT_NAME from request" do
|
|
|
|
get "/awesome/blog/absolute_custom_root"
|
|
|
|
verify_redirect "http://example.org/"
|
2013-10-10 08:01:03 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test "[ENGINE] absolute custom redirect doesn't use SCRIPT_NAME from request" do
|
|
|
|
get "/awesome/blog/absolute_custom_redirect"
|
2014-01-01 06:15:31 -05:00
|
|
|
verify_redirect "http://example.org/foo"
|
2013-10-10 08:01:03 -04:00
|
|
|
end
|
|
|
|
|
2010-07-14 19:18:02 -04:00
|
|
|
# Inside Application
|
|
|
|
test "[APP] generating engine's route includes prefix" do
|
2010-07-09 04:25:10 -04:00
|
|
|
get "/generate"
|
|
|
|
assert_equal "/awesome/blog/posts/1", last_response.body
|
|
|
|
end
|
|
|
|
|
2010-07-14 19:18:02 -04:00
|
|
|
test "[APP] generating engine's route includes default_url_options[:script_name]" do
|
2010-07-09 04:25:10 -04:00
|
|
|
RailsApplication.routes.default_url_options = {:script_name => "/something"}
|
|
|
|
get "/generate"
|
|
|
|
assert_equal "/something/awesome/blog/posts/1", last_response.body
|
2010-07-01 03:04:30 -04:00
|
|
|
end
|
|
|
|
|
2010-07-18 13:49:51 -04:00
|
|
|
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
|
|
|
|
|
2011-06-06 08:13:06 -04:00
|
|
|
test "polymorphic_path_for_app" do
|
|
|
|
get "/polymorphic_path_for_app"
|
|
|
|
assert_equal "/posts/1", last_response.body
|
|
|
|
end
|
|
|
|
|
2010-07-18 13:49:51 -04:00
|
|
|
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
|
|
|
|
|
2012-09-09 02:59:21 -04:00
|
|
|
test "[APP] instance variable with same name as engine" do
|
|
|
|
get "/ivar_usage"
|
|
|
|
assert_equal "/awesome/blog/posts/1", last_response.body
|
|
|
|
end
|
|
|
|
|
2010-07-14 19:18:02 -04:00
|
|
|
# Inside any Object
|
2012-01-03 14:26:45 -05:00
|
|
|
test "[OBJECT] proxy route should override respond_to?() as expected" do
|
|
|
|
assert_respond_to blog_engine, :named_helper_that_should_be_invoked_only_in_respond_to_test_path
|
|
|
|
end
|
|
|
|
|
2010-07-14 19:18:02 -04:00
|
|
|
test "[OBJECT] generating engine's route includes prefix" do
|
|
|
|
assert_equal "/awesome/blog/posts/1", engine_object.post_path(:id => 1)
|
2010-07-01 03:04:30 -04:00
|
|
|
end
|
|
|
|
|
2010-07-14 19:18:02 -04:00
|
|
|
test "[OBJECT] generating engine's route includes dynamic prefix" do
|
|
|
|
assert_equal "/pure-awesomeness/blog/posts/3", engine_object.post_path(:id => 3, :omg => "pure-awesomeness")
|
2010-07-01 03:04:30 -04:00
|
|
|
end
|
|
|
|
|
2010-07-14 19:18:02 -04:00
|
|
|
test "[OBJECT] generating engine's route includes default_url_options[:script_name]" do
|
|
|
|
RailsApplication.routes.default_url_options = {:script_name => "/something"}
|
|
|
|
assert_equal "/something/pure-awesomeness/blog/posts/3", engine_object.post_path(:id => 3, :omg => "pure-awesomeness")
|
2010-07-01 03:04:30 -04:00
|
|
|
end
|
2010-07-07 05:26:03 -04:00
|
|
|
|
2010-07-14 19:18:02 -04:00
|
|
|
test "[OBJECT] generating application's route" do
|
|
|
|
assert_equal "/", app_object.root_path
|
2010-07-09 04:25:10 -04:00
|
|
|
end
|
|
|
|
|
2010-07-14 19:18:02 -04:00
|
|
|
test "[OBJECT] generating application's route includes default_url_options[:script_name]" do
|
2010-07-09 04:25:10 -04:00
|
|
|
RailsApplication.routes.default_url_options = {:script_name => "/something"}
|
2010-07-14 19:18:02 -04:00
|
|
|
assert_equal "/something/", app_object.root_path
|
2010-07-09 04:25:10 -04:00
|
|
|
end
|
|
|
|
|
2012-11-04 08:59:15 -05:00
|
|
|
test "[OBJECT] generating application's route includes default_url_options[:trailing_slash]" do
|
|
|
|
RailsApplication.routes.default_url_options[:trailing_slash] = true
|
|
|
|
assert_equal "/awesome/blog/posts", engine_object.posts_path
|
|
|
|
end
|
|
|
|
|
2010-07-14 19:18:02 -04:00
|
|
|
test "[OBJECT] generating engine's route with url_for" do
|
2010-07-18 13:49:51 -04:00
|
|
|
path = engine_object.url_for(:controller => "inside_engine_generating",
|
2010-07-14 19:18:02 -04:00
|
|
|
:action => "show",
|
|
|
|
:only_path => true,
|
|
|
|
:omg => "omg",
|
|
|
|
:id => 1)
|
|
|
|
assert_equal "/omg/blog/posts/1", path
|
2010-07-18 13:49:51 -04:00
|
|
|
end
|
2010-07-08 17:27:49 -04:00
|
|
|
|
2010-07-18 13:49:51 -04:00
|
|
|
test "[OBJECT] generating engine's route with named helpers" do
|
|
|
|
path = engine_object.posts_path
|
2010-07-14 19:18:02 -04:00
|
|
|
assert_equal "/awesome/blog/posts", path
|
|
|
|
|
2010-07-18 13:49:51 -04:00
|
|
|
path = engine_object.posts_url(:host => "example.com")
|
2010-07-14 19:18:02 -04:00
|
|
|
assert_equal "http://example.com/awesome/blog/posts", path
|
2010-07-07 05:26:03 -04:00
|
|
|
end
|
2010-07-18 13:49:51 -04:00
|
|
|
|
|
|
|
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
|
2014-01-01 06:15:31 -05:00
|
|
|
|
|
|
|
private
|
|
|
|
def verify_redirect(url, status = 301)
|
|
|
|
assert_equal status, last_response.status
|
|
|
|
assert_equal url, last_response.headers["Location"]
|
|
|
|
assert_equal expected_redirect_body(url), last_response.body
|
|
|
|
end
|
|
|
|
|
|
|
|
def expected_redirect_body(url)
|
|
|
|
%(<html><body>You are being <a href="#{url}">redirected</a>.</body></html>)
|
|
|
|
end
|
2010-07-01 03:04:30 -04:00
|
|
|
end
|
2010-09-25 13:22:32 -04:00
|
|
|
|
|
|
|
class EngineMountedAtRoot < ActionDispatch::IntegrationTest
|
|
|
|
include Rack::Test::Methods
|
|
|
|
|
|
|
|
class BlogEngine
|
|
|
|
def self.routes
|
|
|
|
@routes ||= begin
|
|
|
|
routes = ActionDispatch::Routing::RouteSet.new
|
|
|
|
routes.draw do
|
2012-04-24 23:32:09 -04:00
|
|
|
get "/posts/:id", :to => "posts#show", :as => :post
|
2013-10-10 08:01:03 -04:00
|
|
|
|
2014-01-01 06:15:31 -05:00
|
|
|
get "/relative_path_root", :to => redirect("")
|
|
|
|
get "/relative_path_redirect", :to => redirect("foo")
|
|
|
|
get "/relative_option_root", :to => redirect(:path => "")
|
2013-10-10 08:01:03 -04:00
|
|
|
get "/relative_option_redirect", :to => redirect(:path => "foo")
|
2014-01-01 06:15:31 -05:00
|
|
|
get "/relative_custom_root", :to => redirect { |params, request| "" }
|
2013-10-10 08:01:03 -04:00
|
|
|
get "/relative_custom_redirect", :to => redirect { |params, request| "foo" }
|
|
|
|
|
2014-01-01 06:15:31 -05:00
|
|
|
get "/absolute_path_root", :to => redirect("/")
|
|
|
|
get "/absolute_path_redirect", :to => redirect("/foo")
|
|
|
|
get "/absolute_option_root", :to => redirect(:path => "/")
|
2013-10-10 08:01:03 -04:00
|
|
|
get "/absolute_option_redirect", :to => redirect(:path => "/foo")
|
2014-01-01 06:15:31 -05:00
|
|
|
get "/absolute_custom_root", :to => redirect { |params, request| "/" }
|
2013-10-10 08:01:03 -04:00
|
|
|
get "/absolute_custom_redirect", :to => redirect { |params, request| "/foo" }
|
2010-09-25 13:22:32 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
routes
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.call(env)
|
|
|
|
env['action_dispatch.routes'] = routes
|
|
|
|
routes.call(env)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-08-05 19:50:50 -04:00
|
|
|
class RailsApplication < Rails::Engine
|
|
|
|
routes.draw do
|
|
|
|
mount BlogEngine => "/"
|
2010-09-25 13:22:32 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class ::PostsController < ActionController::Base
|
|
|
|
include BlogEngine.routes.url_helpers
|
|
|
|
include RailsApplication.routes.mounted_helpers
|
|
|
|
|
|
|
|
def show
|
|
|
|
render :text => post_path(:id => params[:id])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def app
|
2014-08-05 19:50:50 -04:00
|
|
|
RailsApplication.instance
|
2010-09-25 13:22:32 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test "generating path inside engine" do
|
|
|
|
get "/posts/1"
|
|
|
|
assert_equal "/posts/1", last_response.body
|
|
|
|
end
|
2013-10-10 08:01:03 -04:00
|
|
|
|
2014-01-01 06:15:31 -05:00
|
|
|
test "[ENGINE] relative path root uses SCRIPT_NAME from request" do
|
|
|
|
get "/relative_path_root"
|
|
|
|
verify_redirect "http://example.org/"
|
|
|
|
end
|
|
|
|
|
2013-10-10 08:01:03 -04:00
|
|
|
test "[ENGINE] relative path redirect uses SCRIPT_NAME from request" do
|
|
|
|
get "/relative_path_redirect"
|
2014-01-01 06:15:31 -05:00
|
|
|
verify_redirect "http://example.org/foo"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "[ENGINE] relative option root uses SCRIPT_NAME from request" do
|
|
|
|
get "/relative_option_root"
|
|
|
|
verify_redirect "http://example.org/"
|
2013-10-10 08:01:03 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test "[ENGINE] relative option redirect uses SCRIPT_NAME from request" do
|
|
|
|
get "/relative_option_redirect"
|
2014-01-01 06:15:31 -05:00
|
|
|
verify_redirect "http://example.org/foo"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "[ENGINE] relative custom root uses SCRIPT_NAME from request" do
|
|
|
|
get "/relative_custom_root"
|
|
|
|
verify_redirect "http://example.org/"
|
2013-10-10 08:01:03 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test "[ENGINE] relative custom redirect uses SCRIPT_NAME from request" do
|
|
|
|
get "/relative_custom_redirect"
|
2014-01-01 06:15:31 -05:00
|
|
|
verify_redirect "http://example.org/foo"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "[ENGINE] absolute path root doesn't use SCRIPT_NAME from request" do
|
|
|
|
get "/absolute_path_root"
|
|
|
|
verify_redirect "http://example.org/"
|
2013-10-10 08:01:03 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test "[ENGINE] absolute path redirect doesn't use SCRIPT_NAME from request" do
|
|
|
|
get "/absolute_path_redirect"
|
2014-01-01 06:15:31 -05:00
|
|
|
verify_redirect "http://example.org/foo"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "[ENGINE] absolute option root doesn't use SCRIPT_NAME from request" do
|
|
|
|
get "/absolute_option_root"
|
|
|
|
verify_redirect "http://example.org/"
|
2013-10-10 08:01:03 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test "[ENGINE] absolute option redirect doesn't use SCRIPT_NAME from request" do
|
|
|
|
get "/absolute_option_redirect"
|
2014-01-01 06:15:31 -05:00
|
|
|
verify_redirect "http://example.org/foo"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "[ENGINE] absolute custom root doesn't use SCRIPT_NAME from request" do
|
|
|
|
get "/absolute_custom_root"
|
|
|
|
verify_redirect "http://example.org/"
|
2013-10-10 08:01:03 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test "[ENGINE] absolute custom redirect doesn't use SCRIPT_NAME from request" do
|
|
|
|
get "/absolute_custom_redirect"
|
2014-01-01 06:15:31 -05:00
|
|
|
verify_redirect "http://example.org/foo"
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
def verify_redirect(url, status = 301)
|
|
|
|
assert_equal status, last_response.status
|
|
|
|
assert_equal url, last_response.headers["Location"]
|
|
|
|
assert_equal expected_redirect_body(url), last_response.body
|
|
|
|
end
|
|
|
|
|
|
|
|
def expected_redirect_body(url)
|
|
|
|
%(<html><body>You are being <a href="#{url}">redirected</a>.</body></html>)
|
|
|
|
end
|
2010-09-25 13:22:32 -04:00
|
|
|
end
|
2010-07-01 03:04:30 -04:00
|
|
|
end
|