Skip to content

Commit

Permalink
Merge remote branch 'rails/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
fxn committed Jun 7, 2010
2 parents 0dbc732 + 1a8f784 commit 9e065c6
Show file tree
Hide file tree
Showing 34 changed files with 266 additions and 189 deletions.
2 changes: 1 addition & 1 deletion actionpack/actionpack.gemspec
Expand Up @@ -22,7 +22,7 @@ Gem::Specification.new do |s|
s.add_dependency('activesupport', version)
s.add_dependency('activemodel', version)
s.add_dependency('builder', '~> 2.1.2')
s.add_dependency('i18n', '~> 0.4.0')
s.add_dependency('i18n', '~> 0.4.1')
s.add_dependency('rack', '~> 1.1.0')
s.add_dependency('rack-test', '~> 0.5.4')
s.add_dependency('rack-mount', '~> 0.6.3')
Expand Down
12 changes: 7 additions & 5 deletions actionpack/lib/action_controller/test_case.rb
Expand Up @@ -139,14 +139,16 @@ def assign_parameters(routes, controller_path, action, parameters = {})
end
end

params = self.request_parameters.dup
# Clear the combined params hash in case it was already referenced.
@env.delete("action_dispatch.request.parameters")

params = self.request_parameters.dup
%w(controller action only_path).each do |k|
params.delete(k)
params.delete(k.to_sym)
end

data = params.to_query

@env['CONTENT_LENGTH'] = data.length.to_s
@env['rack.input'] = StringIO.new(data)
end
Expand All @@ -155,6 +157,8 @@ def recycle!
@formats = nil
@env.delete_if { |k, v| k =~ /^(action_dispatch|rack)\.request/ }
@env.delete_if { |k, v| k =~ /^action_dispatch\.rescue/ }
@method = @request_method = nil
@fullpath = @ip = @remote_ip = nil
@env['action_dispatch.request.query_parameters'] = {}
end
end
Expand All @@ -167,9 +171,7 @@ def recycle!
@block = nil
@length = 0
@body = []
@charset = nil
@content_type = nil

@charset = @content_type = nil
@request = @template = nil
end
end
Expand Down
26 changes: 19 additions & 7 deletions actionpack/lib/action_dispatch/http/request.rb
Expand Up @@ -52,9 +52,11 @@ def key?(key)
# the application should use), this \method returns the overridden
# value, not the original.
def request_method
method = env["REQUEST_METHOD"]
HTTP_METHOD_LOOKUP[method] || raise(ActionController::UnknownHttpMethod, "#{method}, accepted HTTP methods are #{HTTP_METHODS.to_sentence(:locale => :en)}")
method
@request_method ||= begin
method = env["REQUEST_METHOD"]
HTTP_METHOD_LOOKUP[method] || raise(ActionController::UnknownHttpMethod, "#{method}, accepted HTTP methods are #{HTTP_METHODS.to_sentence(:locale => :en)}")
method
end
end

# Returns a symbol form of the #request_method
Expand All @@ -66,9 +68,11 @@ def request_method_symbol
# even if it was overridden by middleware. See #request_method for
# more information.
def method
method = env["rack.methodoverride.original_method"] || env['REQUEST_METHOD']
HTTP_METHOD_LOOKUP[method] || raise(ActionController::UnknownHttpMethod, "#{method}, accepted HTTP methods are #{HTTP_METHODS.to_sentence(:locale => :en)}")
method
@method ||= begin
method = env["rack.methodoverride.original_method"] || env['REQUEST_METHOD']
HTTP_METHOD_LOOKUP[method] || raise(ActionController::UnknownHttpMethod, "#{method}, accepted HTTP methods are #{HTTP_METHODS.to_sentence(:locale => :en)}")
method
end
end

# Returns a symbol form of the #method
Expand Down Expand Up @@ -113,6 +117,10 @@ def headers
Http::Headers.new(@env)
end

def fullpath
@fullpath ||= super
end

def forgery_whitelisted?
get? || xhr? || content_mime_type.nil? || !content_mime_type.verify_request?
end
Expand All @@ -134,6 +142,10 @@ def xml_http_request?
end
alias :xhr? :xml_http_request?

def ip
@ip ||= super
end

# Which IP addresses are "trusted proxies" that can be stripped from
# the right-hand-side of X-Forwarded-For
TRUSTED_PROXIES = /^127\.0\.0\.1$|^(10|172\.(1[6-9]|2[0-9]|30|31)|192\.168)\./i
Expand All @@ -145,7 +157,7 @@ def xml_http_request?
# delimited list in the case of multiple chained proxies; the last
# address which is not trusted is the originating IP.
def remote_ip
(@env["action_dispatch.remote_ip"] || ip).to_s
@remote_ip ||= (@env["action_dispatch.remote_ip"] || ip).to_s
end

# Returns the lowercase name of the HTTP server software.
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_dispatch/middleware/flash.rb
Expand Up @@ -176,7 +176,7 @@ def call(env)

@app.call(env)
ensure
if (session = env['rack.session']) && (flash = session['flash']) && flash.empty?
if (session = env['rack.session']) && session.key?('flash') && session['flash'].empty?
session.delete('flash')
end
end
Expand Down
Expand Up @@ -51,11 +51,11 @@ def inspect
super
end

private
def loaded?
@loaded
end
def loaded?
@loaded
end

private
def load!
stale_session_check! do
id, session = @by.send(:load_session, @env)
Expand Down
Expand Up @@ -72,7 +72,7 @@ def render_exception(env, exception)
rescue_action_in_public(exception)
end
rescue Exception => failsafe_error
$stderr.puts "Error during failsafe response: #{failsafe_error}"
$stderr.puts "Error during failsafe response: #{failsafe_error}\n #{failsafe_error.backtrace * "\n "}"
FAILSAFE_RESPONSE
end

Expand Down
18 changes: 5 additions & 13 deletions actionpack/lib/action_dispatch/middleware/stack.rb
Expand Up @@ -5,13 +5,13 @@ class MiddlewareStack < Array
class Middleware
attr_reader :args, :block

def initialize(klass, *args, &block)
@klass, @args, @block = klass, args, block
def initialize(klass_or_name, *args, &block)
@ref = ActiveSupport::Dependencies::Reference.new(klass_or_name)
@args, @block = args, block
end

def klass
return @klass if @klass.respond_to?(:new)
@klass = ActiveSupport::Inflector.constantize(@klass.to_s)
@ref.get
end

def ==(middleware)
Expand All @@ -21,11 +21,7 @@ def ==(middleware)
when Class
klass == middleware
else
if lazy_compare?(@klass) && lazy_compare?(middleware)
normalize(@klass) == normalize(middleware)
else
klass.name == normalize(middleware.to_s)
end
normalize(@ref.name) == normalize(middleware)
end
end

Expand All @@ -39,10 +35,6 @@ def build(app)

private

def lazy_compare?(object)
object.is_a?(String) || object.is_a?(Symbol)
end

def normalize(object)
object.to_s.strip.sub(/^::/, '')
end
Expand Down
Expand Up @@ -13,7 +13,7 @@
request_dump = clean_params.empty? ? 'None' : clean_params.inspect.gsub(',', ",\n")

def debug_hash(hash)
hash.sort_by { |k, v| k.to_s }.map { |k, v| "#{k}: #{v.inspect}" }.join("\n")
hash.sort_by { |k, v| k.to_s }.map { |k, v| "#{k}: #{v.inspect rescue $!.message}" }.join("\n")
end
%>

Expand Down
15 changes: 11 additions & 4 deletions actionpack/lib/action_dispatch/routing/mapper.rb
Expand Up @@ -622,12 +622,19 @@ def collection
end

def member
unless @scope[:scope_level] == :resources
raise ArgumentError, "can't use member outside resources scope"
unless [:resources, :resource].include?(@scope[:scope_level])
raise ArgumentError, "You can't use member action outside resources and resource scope."
end

with_scope_level(:member) do
scope(':id', :name_prefix => parent_resource.member_name, :as => "") do
case @scope[:scope_level]
when :resources
with_scope_level(:member) do
scope(':id', :name_prefix => parent_resource.member_name, :as => "") do
yield
end
end
when :resource
with_scope_level(:member) do
yield
end
end
Expand Down
27 changes: 17 additions & 10 deletions actionpack/lib/action_dispatch/routing/route_set.rb
Expand Up @@ -12,6 +12,7 @@ class Dispatcher #:nodoc:
def initialize(options={})
@defaults = options[:defaults]
@glob_param = options.delete(:glob)
@controllers = {}
end

def call(env)
Expand All @@ -29,19 +30,18 @@ def call(env)
def prepare_params!(params)
merge_default_action!(params)
split_glob_param!(params) if @glob_param

params.each do |key, value|
if value.is_a?(String)
value = value.dup.force_encoding(Encoding::BINARY) if value.respond_to?(:force_encoding)
params[key] = URI.unescape(value)
end
end
end

def controller(params, raise_error=true)
if params && params.has_key?(:controller)
controller = "#{params[:controller].camelize}Controller"
ActiveSupport::Inflector.constantize(controller)
if params && params.key?(:controller)
controller_param = params[:controller]
unless controller = @controllers[controller_param]
controller_name = "#{controller_param.camelize}Controller"
controller = @controllers[controller_param] =
ActiveSupport::Dependencies.ref(controller_name)
end

controller.get
end
rescue NameError => e
raise ActionController::RoutingError, e.message, e.backtrace if raise_error
Expand Down Expand Up @@ -466,6 +466,13 @@ def recognize_path(path, environment = {})

req = Rack::Request.new(env)
@set.recognize(req) do |route, matches, params|
params.each do |key, value|
if value.is_a?(String)
value = value.dup.force_encoding(Encoding::BINARY) if value.encoding_aware?
params[key] = URI.unescape(value)
end
end

dispatcher = route.app
if dispatcher.is_a?(Dispatcher) && dispatcher.controller(params, false)
dispatcher.prepare_params!(params)
Expand Down
3 changes: 2 additions & 1 deletion actionpack/lib/action_view/base.rb
Expand Up @@ -184,7 +184,7 @@ class << self
attr_internal :captures, :request, :controller, :template, :config

delegate :find_template, :template_exists?, :formats, :formats=, :locale, :locale=,
:view_paths, :view_paths=, :with_fallbacks, :update_details, :to => :lookup_context
:view_paths, :view_paths=, :with_fallbacks, :update_details, :with_layout_format, :to => :lookup_context

delegate :request_forgery_protection_token, :template, :params, :session, :cookies, :response, :headers,
:flash, :action_name, :controller_name, :to => :controller
Expand All @@ -201,6 +201,7 @@ def self.xss_safe? #:nodoc:
end

def self.process_view_paths(value)
return value.dup if value.is_a?(PathSet)
ActionView::PathSet.new(Array.wrap(value))
end

Expand Down

2 comments on commit 9e065c6

@stid
Copy link

@stid stid commented on 9e065c6 Jun 7, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"all_hashes" method is gone with this merge. Is this ok?

@jeremy
Copy link
Member

@jeremy jeremy commented on 9e065c6 Jun 7, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it's intentional. It was actually removed in a5f3f3e.

Please sign in to comment.