Skip to content
This repository was archived by the owner on May 5, 2020. It is now read-only.

Journey #7

Open
wants to merge 38 commits into
base: 2-3-github
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
6d4d9dd
copy/paste router from 3-0-github
tmm1 Mar 26, 2013
9ee6c6c
import activesupport dependencies
tmm1 Mar 26, 2013
d98e3f8
remove UrlWriter
tmm1 Mar 27, 2013
3297a4c
integrate backported router
tmm1 Mar 27, 2013
e3dafa5
fix references to ActiveModel from bad merge
tmm1 Mar 28, 2013
0e467e3
PathSegment is gone
tmm1 Mar 28, 2013
735c4e7
rewrite_options is dead
tmm1 Mar 28, 2013
b75d7ea
fix integration runner
tmm1 Mar 29, 2013
5787193
AS deps from rails master
tmm1 Mar 29, 2013
d22470a
import journey from rails master
tmm1 Mar 29, 2013
b86cf68
backport router from rails master
tmm1 Mar 29, 2013
370b93b
name_prefix and 1.8 compat
tmm1 Mar 29, 2013
73e5333
more AS core ext from rails master
tmm1 Mar 30, 2013
0fee4d2
remove rack hack
tmm1 Mar 30, 2013
7ffe8e6
more fixes missed in merge
tmm1 Mar 30, 2013
6372a64
s/request_method/request_method_string/ for rails2.3 compat
tmm1 Mar 30, 2013
6fc589d
ruby1.8 compat
tmm1 Mar 31, 2013
1744654
kill require for deleted file
tmm1 Mar 31, 2013
32295bb
remove name_prefix compat layer
tmm1 Mar 31, 2013
96b2115
1.8 compat
tmm1 Mar 31, 2013
5c84664
more 1.8 compat
tmm1 Mar 31, 2013
46e7ead
fix helper installation in integration tests
tmm1 Mar 31, 2013
a390e03
update assert_redirected_to to use location header
tmm1 Apr 1, 2013
fa6c421
set content-length for rack::lint
tmm1 Apr 1, 2013
d4eac0f
hook up new routes to test suite
tmm1 Apr 1, 2013
54a1b2a
make sure controller request is not nil
tmm1 Apr 1, 2013
0749c45
1.8 compat
tmm1 Apr 1, 2013
31ba117
skip query string on post requests
tmm1 Apr 1, 2013
a431bb5
more 1.8 compat
tmm1 Apr 1, 2013
ceb7b06
skip blank prefixed names
tmm1 Apr 1, 2013
26946cd
kill controller_constraints
tmm1 Apr 1, 2013
cfe841a
add required_defaults to deprecated mapper
tmm1 Apr 1, 2013
536b85e
raise RoutingError to let rails2.3 machinery handle 404s
tmm1 Apr 2, 2013
b2321ce
Merge branch '2-3-github' into journey
tmm1 Jan 15, 2014
89384ac
missing requires
tmm1 Jan 15, 2014
77934cb
Merge remote-tracking branch 'origin/2-3-github' into journey
tmm1 Jan 15, 2014
39b441b
polymorphic routes are gone
tmm1 Jan 15, 2014
94fe079
define routes for tests
tmm1 Jan 15, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion actionmailer/lib/action_mailer/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ module ActionMailer #:nodoc:
class Base
include AdvAttrAccessor, PartContainer, Quoting, Utils
if Object.const_defined?(:ActionController)
include ActionController::UrlWriter
include ActionController::Layout
end

Expand Down
2 changes: 1 addition & 1 deletion actionpack/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ spec = Gem::Specification.new do |s|

s.add_dependency('activesupport', '= 2.3.14' + PKG_BUILD)
s.add_dependency('erubis', '~> 2.7.0')
s.add_dependency('rack', '~> 1.1')
s.add_dependency('rack', '~> 1.1')

s.require_path = 'lib'

Expand Down
4 changes: 1 addition & 3 deletions actionpack/lib/action_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module ActionController
# TODO: Review explicit to see if they will automatically be handled by
# the initilizer if they are really needed.
def self.load_all!
[Base, Request, Response, Http::Headers, UrlRewriter, UrlWriter]
[Base, Request, Response, Http::Headers, UrlRewriter]
end

autoload :Base, 'action_controller/base'
Expand All @@ -57,7 +57,6 @@ def self.load_all!
autoload :MiddlewareStack, 'action_controller/middleware_stack'
autoload :MimeResponds, 'action_controller/mime_responds'
autoload :ParamsParser, 'action_controller/params_parser'
autoload :PolymorphicRoutes, 'action_controller/polymorphic_routes'
autoload :RecordIdentifier, 'action_controller/record_identifier'
autoload :Reloader, 'action_controller/reloader'
autoload :Request, 'action_controller/request'
Expand All @@ -78,7 +77,6 @@ def self.load_all!
autoload :UploadedStringIO, 'action_controller/uploaded_file'
autoload :UploadedTempfile, 'action_controller/uploaded_file'
autoload :UrlRewriter, 'action_controller/url_rewriter'
autoload :UrlWriter, 'action_controller/url_rewriter'
autoload :Verification, 'action_controller/verification'

module Assertions
Expand Down
14 changes: 2 additions & 12 deletions actionpack/lib/action_controller/assertions/response_assertions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,9 @@ def assert_response(type, message = nil)
def assert_redirected_to(options = {}, message=nil)
clean_backtrace do
assert_response(:redirect, message)
return true if options == @response.redirected_to
return true if options == @response.location

# Support partial arguments for hash redirections
if options.is_a?(Hash) && @response.redirected_to.is_a?(Hash)
if options.all? {|(key, value)| @response.redirected_to[key] == value}
callstack = caller.dup
callstack.slice!(0, 2)
::ActiveSupport::Deprecation.warn("Using assert_redirected_to with partial hash arguments is deprecated. Specify the full set arguments instead", callstack)
return true
end
end

redirected_to_after_normalisation = normalize_argument_to_redirection(@response.redirected_to)
redirected_to_after_normalisation = normalize_argument_to_redirection(@response.location)
options_after_normalisation = normalize_argument_to_redirection(options)

if redirected_to_after_normalisation != options_after_normalisation
Expand Down
167 changes: 6 additions & 161 deletions actionpack/lib/action_controller/base.rb
Original file line number Diff line number Diff line change
@@ -1,61 +1,15 @@
require 'set'
require 'action_controller/metal/url_for'
require 'action_controller/metal/exceptions'

module ActionController #:nodoc:
class ActionControllerError < StandardError #:nodoc:
end

class SessionRestoreError < ActionControllerError #:nodoc:
end

class RenderError < ActionControllerError #:nodoc:
end

class RoutingError < ActionControllerError #:nodoc:
attr_reader :failures
def initialize(message, failures=[])
super(message)
@failures = failures
end
end

class MethodNotAllowed < ActionControllerError #:nodoc:
attr_reader :allowed_methods

def initialize(*allowed_methods)
super("Only #{allowed_methods.to_sentence(:locale => :en)} requests are allowed.")
@allowed_methods = allowed_methods
end

def allowed_methods_header
allowed_methods.map { |method_symbol| method_symbol.to_s.upcase } * ', '
end

def handle_response!(response)
response.headers['Allow'] ||= allowed_methods_header
end
end

class NotImplemented < MethodNotAllowed #:nodoc:
end

class UnknownController < ActionControllerError #:nodoc:
end

class UnknownAction < ActionControllerError #:nodoc:
end

class MissingFile < ActionControllerError #:nodoc:
end

class RenderError < ActionControllerError #:nodoc:
end

class SessionOverflowError < ActionControllerError #:nodoc:
DEFAULT_MESSAGE = 'Your session data is larger than the data column in which it is to be stored. You must increase the size of your data column if you intend to store large data.'

def initialize(message = nil)
super(message || DEFAULT_MESSAGE)
end
class SessionRestoreError < ActionControllerError #:nodoc:
end

class DoubleRenderError < ActionControllerError #:nodoc:
Expand All @@ -74,9 +28,6 @@ def initialize(message = nil)
end
end

class UnknownHttpMethod < ActionControllerError #:nodoc:
end

# Action Controllers are the core of a web request in Rails. They are made up of one or more actions that are executed
# on request and then either render a template or redirect to another action. An action is defined as a public method
# on the controller, which will automatically be made accessible to the web-server through Rails Routes.
Expand Down Expand Up @@ -250,6 +201,7 @@ class Base
DEFAULT_RENDER_STATUS_CODE = "200 OK"

include StatusCodes
include UrlFor

cattr_reader :protected_instance_variables
# Controller specific instance variables which will not be accessible inside views.
Expand Down Expand Up @@ -541,93 +493,6 @@ def send_response
response
end

# Returns a URL that has been rewritten according to the options hash and the defined routes.
# (For doing a complete redirect, use +redirect_to+).
#
# <tt>url_for</tt> is used to:
#
# All keys given to +url_for+ are forwarded to the Route module, save for the following:
# * <tt>:anchor</tt> - Specifies the anchor name to be appended to the path. For example,
# <tt>url_for :controller => 'posts', :action => 'show', :id => 10, :anchor => 'comments'</tt>
# will produce "/posts/show/10#comments".
# * <tt>:only_path</tt> - If true, returns the relative URL (omitting the protocol, host name, and port) (<tt>false</tt> by default).
# * <tt>:trailing_slash</tt> - If true, adds a trailing slash, as in "/archive/2005/". Note that this
# is currently not recommended since it breaks caching.
# * <tt>:host</tt> - Overrides the default (current) host if provided.
# * <tt>:protocol</tt> - Overrides the default (current) protocol if provided.
# * <tt>:port</tt> - Optionally specify the port to connect to.
# * <tt>:user</tt> - Inline HTTP authentication (only plucked out if <tt>:password</tt> is also present).
# * <tt>:password</tt> - Inline HTTP authentication (only plucked out if <tt>:user</tt> is also present).
# * <tt>:skip_relative_url_root</tt> - If true, the url is not constructed using the +relative_url_root+
# of the request so the path will include the web server relative installation directory.
#
# The URL is generated from the remaining keys in the hash. A URL contains two key parts: the <base> and a query string.
# Routes composes a query string as the key/value pairs not included in the <base>.
#
# The default Routes setup supports a typical Rails path of "controller/action/id" where action and id are optional, with
# action defaulting to 'index' when not given. Here are some typical url_for statements and their corresponding URLs:
#
# url_for :controller => 'posts', :action => 'recent' # => 'proto://host.com/posts/recent'
# url_for :controller => 'posts', :action => 'index' # => 'proto://host.com/posts'
# url_for :controller => 'posts', :action => 'index', :port=>'8033' # => 'proto://host.com:8033/posts'
# url_for :controller => 'posts', :action => 'show', :id => 10 # => 'proto://host.com/posts/show/10'
# url_for :controller => 'posts', :user => 'd', :password => '123' # => 'proto://d:[email protected]/posts'
#
# When generating a new URL, missing values may be filled in from the current request's parameters. For example,
# <tt>url_for :action => 'some_action'</tt> will retain the current controller, as expected. This behavior extends to
# other parameters, including <tt>:controller</tt>, <tt>:id</tt>, and any other parameters that are placed into a Route's
# path.
#  
# The URL helpers such as <tt>url_for</tt> have a limited form of memory: when generating a new URL, they can look for
# missing values in the current request's parameters. Routes attempts to guess when a value should and should not be
# taken from the defaults. There are a few simple rules on how this is performed:
#
# * If the controller name begins with a slash no defaults are used:
#
# url_for :controller => '/home'
#
# In particular, a leading slash ensures no namespace is assumed. Thus,
# while <tt>url_for :controller => 'users'</tt> may resolve to
# <tt>Admin::UsersController</tt> if the current controller lives under
# that module, <tt>url_for :controller => '/users'</tt> ensures you link
# to <tt>::UsersController</tt> no matter what.
# * If the controller changes, the action will default to index unless provided
#
# The final rule is applied while the URL is being generated and is best illustrated by an example. Let us consider the
# route given by <tt>map.connect 'people/:last/:first/:action', :action => 'bio', :controller => 'people'</tt>.
#
# Suppose that the current URL is "people/hh/david/contacts". Let's consider a few different cases of URLs which are generated
# from this page.
#
# * <tt>url_for :action => 'bio'</tt> -- During the generation of this URL, default values will be used for the first and
# last components, and the action shall change. The generated URL will be, "people/hh/david/bio".
# * <tt>url_for :first => 'davids-little-brother'</tt> This generates the URL 'people/hh/davids-little-brother' -- note
# that this URL leaves out the assumed action of 'bio'.
#
# However, you might ask why the action from the current request, 'contacts', isn't carried over into the new URL. The
# answer has to do with the order in which the parameters appear in the generated path. In a nutshell, since the
# value that appears in the slot for <tt>:first</tt> is not equal to default value for <tt>:first</tt> we stop using
# defaults. On its own, this rule can account for much of the typical Rails URL behavior.
#  
# Although a convenience, defaults can occasionally get in your way. In some cases a default persists longer than desired.
# The default may be cleared by adding <tt>:name => nil</tt> to <tt>url_for</tt>'s options.
# This is often required when writing form helpers, since the defaults in play may vary greatly depending upon where the
# helper is used from. The following line will redirect to PostController's default action, regardless of the page it is
# displayed on:
#
# url_for :controller => 'posts', :action => nil
def url_for(options = {})
options ||= {}
case options
when String
options
when Hash
@url.rewrite(rewrite_options(options))
else
polymorphic_url(options)
end
end

# Converts the class name from something like "OneModule::TwoModule::NeatController" to "NeatController".
def controller_class_name
self.class.controller_class_name
Expand Down Expand Up @@ -1035,27 +900,6 @@ def erase_results #:nodoc:
erase_redirect_results
end

def rewrite_options(options) #:nodoc:
if defaults = default_url_options(options)
defaults.merge(options)
else
options
end
end

# Overwrite to implement a number of default options that all url_for-based methods will use. The default options should come in
# the form of a hash, just like the one you would use for url_for directly. Example:
#
# def default_url_options(options)
# { :project => @project.active? ? @project.url_name : "unknown" }
# end
#
# As you can infer from the example, this is mostly useful for situations where you want to centralize dynamic decisions about the
# urls as they stem from the business domain. Please note that any individual url_for call can always override the defaults set
# by this method.
def default_url_options(options = nil)
end

# Redirects the browser to the target specified in +options+. This parameter can take one of three forms:
#
# * <tt>Hash</tt> - The URL will be generated by calling url_for with the +options+.
Expand Down Expand Up @@ -1362,7 +1206,8 @@ def self.action_methods
# Be sure to include shadowed public instance methods of this class
public_instance_methods(false).map { |m| m.to_s } -
# And always exclude explicitly hidden actions
hidden_actions
hidden_actions -
_routes.named_routes.helper_names
end

def reset_variables_added_to_assigns
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_controller/dispatcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def reload_application
# Run prepare callbacks before every request in development mode
run_prepare_callbacks

Routing::Routes.reload
ActionController::Routing.routes_reloader.execute_if_updated
end

def cleanup_application
Expand Down
1 change: 1 addition & 0 deletions actionpack/lib/action_controller/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def master_helper_class

@master_helper_class = Class.new(ActionView::Base).tap do |klass|
klass.send(:include, master_helper_module)
klass.send(:include, ActionController::Routing::Routes.url_helpers)
end
end

Expand Down
21 changes: 11 additions & 10 deletions actionpack/lib/action_controller/integration.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require 'stringio'
require 'uri'
require 'active_support/test_case'
require 'action_controller/rack_lint_patch'

module ActionController
module Integration #:nodoc:
Expand Down Expand Up @@ -91,12 +90,9 @@ def reset!

unless defined? @named_routes_configured
# install the named routes in this session instance.
klass = class << self; self; end
Routing::Routes.install_helpers(klass)

# the helpers are made protected by default--we make them public for
# easier access during testing and troubleshooting.
klass.module_eval { public *Routing::Routes.named_routes.helpers }
class << self
include ActionController::Routing::Routes.url_helpers
end
@named_routes_configured = true
end
end
Expand Down Expand Up @@ -130,7 +126,7 @@ def host!(name)
# performed on the location header.
def follow_redirect!
raise "not a redirect! #{@status} #{@status_message}" unless redirect?
get(interpret_uri(headers['location']))
get(headers['location'])
status
end

Expand Down Expand Up @@ -256,14 +252,15 @@ def interpret_uri(path)

# Performs the actual request.
def process(method, path, parameters = nil, headers = nil)
data = requestify(parameters)
data = requestify(parameters) if !parameters.blank?
path = interpret_uri(path) if path =~ %r{://}
path = "/#{path}" unless path[0] == ?/
path, query = path.split('?', 2)
@path = path
env = {}

if method == :get
env["QUERY_STRING"] = data
env["QUERY_STRING"] = query || data
data = nil
end

Expand Down Expand Up @@ -343,6 +340,10 @@ def process(method, path, parameters = nil, headers = nil)
@response = @controller.response
@controller.send(:set_test_assigns)
else
# Fake request for integration tests that never hit a controller ('/' => redirect('/abc'))
@request = ActionController::TestRequest.new
@request.host = host

# Decorate responses from Rack Middleware and Rails Metal
# as an Response for the purposes of integration testing
@response = Response.new
Expand Down
Loading