mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Sync 'rails/rails/master'
This commit is contained in:
@@ -384,8 +384,8 @@ module ActionController #:nodoc:
|
||||
class << self
|
||||
def call(env)
|
||||
# HACK: For global rescue to have access to the original request and response
|
||||
request = env["actioncontroller.rescue.request"] ||= Request.new(env)
|
||||
response = env["actioncontroller.rescue.response"] ||= Response.new
|
||||
request = env["action_controller.rescue.request"] ||= Request.new(env)
|
||||
response = env["action_controller.rescue.response"] ||= Response.new
|
||||
process(request, response)
|
||||
end
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@ module ActionController
|
||||
# Development mode callbacks
|
||||
before_dispatch :reload_application
|
||||
after_dispatch :cleanup_application
|
||||
|
||||
ActionView::Helpers::AssetTagHelper.cache_asset_timestamps = false
|
||||
end
|
||||
|
||||
if defined?(ActiveRecord)
|
||||
|
||||
@@ -19,6 +19,7 @@ module ActionController
|
||||
|
||||
def initialize(env)
|
||||
@env = env
|
||||
@parser = ActionController::RequestParser.new(env)
|
||||
end
|
||||
|
||||
%w[ AUTH_TYPE GATEWAY_INTERFACE PATH_INFO
|
||||
@@ -92,16 +93,15 @@ module ActionController
|
||||
|
||||
# Returns the content length of the request as an integer.
|
||||
def content_length
|
||||
@env['CONTENT_LENGTH'].to_i
|
||||
@env["action_controller.request.content_length"] ||= @env['CONTENT_LENGTH'].to_i
|
||||
end
|
||||
memoize :content_length
|
||||
|
||||
# The MIME type of the HTTP request, such as Mime::XML.
|
||||
#
|
||||
# For backward compatibility, the post \format is extracted from the
|
||||
# X-Post-Data-Format HTTP header if present.
|
||||
def content_type
|
||||
Mime::Type.lookup(parser.content_type_without_parameters)
|
||||
Mime::Type.lookup(@parser.content_type_without_parameters)
|
||||
end
|
||||
memoize :content_type
|
||||
|
||||
@@ -398,7 +398,7 @@ EOM
|
||||
# Read the request \body. This is useful for web services that need to
|
||||
# work with raw requests directly.
|
||||
def raw_post
|
||||
parser.raw_post
|
||||
@parser.raw_post
|
||||
end
|
||||
|
||||
# Returns both GET and POST \parameters in a single hash.
|
||||
@@ -427,7 +427,7 @@ EOM
|
||||
end
|
||||
|
||||
def body
|
||||
parser.body
|
||||
@parser.body
|
||||
end
|
||||
|
||||
def remote_addr
|
||||
@@ -440,11 +440,11 @@ EOM
|
||||
alias referer referrer
|
||||
|
||||
def query_parameters
|
||||
@query_parameters ||= parser.query_parameters
|
||||
@parser.query_parameters
|
||||
end
|
||||
|
||||
def request_parameters
|
||||
@request_parameters ||= parser.request_parameters
|
||||
@parser.request_parameters
|
||||
end
|
||||
|
||||
def body_stream #:nodoc:
|
||||
@@ -460,7 +460,7 @@ EOM
|
||||
end
|
||||
|
||||
def session=(session) #:nodoc:
|
||||
@session = session
|
||||
@env['rack.session'] = session
|
||||
end
|
||||
|
||||
def reset_session
|
||||
@@ -483,9 +483,5 @@ EOM
|
||||
def named_host?(host)
|
||||
!(host.nil? || /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.match(host))
|
||||
end
|
||||
|
||||
def parser
|
||||
@parser ||= ActionController::RequestParser.new(@env)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,14 +2,15 @@ module ActionController
|
||||
class RequestParser
|
||||
def initialize(env)
|
||||
@env = env
|
||||
freeze
|
||||
end
|
||||
|
||||
def request_parameters
|
||||
@request_parameters ||= parse_formatted_request_parameters
|
||||
@env["action_controller.request_parser.request_parameters"] ||= parse_formatted_request_parameters
|
||||
end
|
||||
|
||||
def query_parameters
|
||||
@query_parameters ||= self.class.parse_query_parameters(query_string)
|
||||
@env["action_controller.request_parser.query_parameters"] ||= self.class.parse_query_parameters(query_string)
|
||||
end
|
||||
|
||||
# Returns the query string, accounting for server idiosyncrasies.
|
||||
@@ -90,7 +91,7 @@ module ActionController
|
||||
end
|
||||
|
||||
def content_length
|
||||
@content_length ||= @env['CONTENT_LENGTH'].to_i
|
||||
@env["action_controller.request.content_length"] ||= @env['CONTENT_LENGTH'].to_i
|
||||
end
|
||||
|
||||
# The raw content type string. Use when you need parameters such as
|
||||
|
||||
@@ -60,8 +60,8 @@ module ActionController #:nodoc:
|
||||
|
||||
module ClassMethods
|
||||
def call_with_exception(env, exception) #:nodoc:
|
||||
request = env["actioncontroller.rescue.request"] ||= Request.new(env)
|
||||
response = env["actioncontroller.rescue.response"] ||= Response.new
|
||||
request = env["action_controller.rescue.request"] ||= Request.new(env)
|
||||
response = env["action_controller.rescue.response"] ||= Response.new
|
||||
new.process(request, response, :rescue_action, exception)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -468,6 +468,22 @@ module ActionView
|
||||
tag("img", options)
|
||||
end
|
||||
|
||||
def self.cache_asset_timestamps
|
||||
@@cache_asset_timestamps
|
||||
end
|
||||
|
||||
# You can enable or disable the asset tag timestamps cache.
|
||||
# With the cache enabled, the asset tag helper methods will make fewer
|
||||
# expense file system calls. However this prevents you from modifying
|
||||
# any asset files while the server is running.
|
||||
#
|
||||
# ActionView::Helpers::AssetTagHelper.cache_asset_timestamps = false
|
||||
def self.cache_asset_timestamps=(value)
|
||||
@@cache_asset_timestamps = value
|
||||
end
|
||||
|
||||
@@cache_asset_timestamps = true
|
||||
|
||||
private
|
||||
# Add the the extension +ext+ if not present. Return full URLs otherwise untouched.
|
||||
# Prefix with <tt>/dir/</tt> if lacking a leading +/+. Account for relative URL
|
||||
@@ -526,18 +542,28 @@ module ActionView
|
||||
end
|
||||
end
|
||||
|
||||
@@asset_timestamps_cache = {}
|
||||
@@asset_timestamps_cache_guard = Mutex.new
|
||||
|
||||
# Use the RAILS_ASSET_ID environment variable or the source's
|
||||
# modification time as its cache-busting asset id.
|
||||
def rails_asset_id(source)
|
||||
if asset_id = ENV["RAILS_ASSET_ID"]
|
||||
asset_id
|
||||
else
|
||||
path = File.join(ASSETS_DIR, source)
|
||||
|
||||
if File.exist?(path)
|
||||
File.mtime(path).to_i.to_s
|
||||
if @@cache_asset_timestamps && (asset_id = @@asset_timestamps_cache[source])
|
||||
asset_id
|
||||
else
|
||||
''
|
||||
path = File.join(ASSETS_DIR, source)
|
||||
asset_id = File.exist?(path) ? File.mtime(path).to_i.to_s : ''
|
||||
|
||||
if @@cache_asset_timestamps
|
||||
@@asset_timestamps_cache_guard.synchronize do
|
||||
@@asset_timestamps_cache[source] = asset_id
|
||||
end
|
||||
end
|
||||
|
||||
asset_id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -391,8 +391,8 @@ class RequestTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
def test_parameters
|
||||
@request.instance_eval { @request_parameters = { "foo" => 1 } }
|
||||
@request.instance_eval { @query_parameters = { "bar" => 2 } }
|
||||
@request.stubs(:request_parameters).returns({ "foo" => 1 })
|
||||
@request.stubs(:query_parameters).returns({ "bar" => 2 })
|
||||
|
||||
assert_equal({"foo" => 1, "bar" => 2}, @request.parameters)
|
||||
assert_equal({"foo" => 1}, @request.request_parameters)
|
||||
|
||||
@@ -383,8 +383,8 @@ class RescueControllerTest < ActionController::TestCase
|
||||
|
||||
def test_rescue_dispatcher_exceptions
|
||||
env = @request.env
|
||||
env["actioncontroller.rescue.request"] = @request
|
||||
env["actioncontroller.rescue.response"] = @response
|
||||
env["action_controller.rescue.request"] = @request
|
||||
env["action_controller.rescue.response"] = @response
|
||||
|
||||
RescueController.call_with_exception(env, ActionController::RoutingError.new("Route not found"))
|
||||
assert_equal "no way", @response.body
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
*2.3.0 [Edge]*
|
||||
|
||||
* TimeWithZone#- gives correct result with wrapped DateTime, and with DateTime argument [Geoff Buesing]
|
||||
|
||||
* Updated i18n gem to version 0.1.1 #1635 [Yaroslav Markin]
|
||||
|
||||
* Add :allow_nil option to delegate. #1127 [Sergio Gil]
|
||||
|
||||
@@ -199,7 +199,7 @@ module ActiveSupport
|
||||
# If we're subtracting a Duration of variable length (i.e., years, months, days), move backwards from #time,
|
||||
# otherwise move backwards #utc, for accuracy when moving across DST boundaries
|
||||
if other.acts_like?(:time)
|
||||
utc - other
|
||||
utc.to_f - other.to_f
|
||||
elsif duration_of_variable_length?(other)
|
||||
method_missing(:-, other)
|
||||
else
|
||||
|
||||
@@ -256,6 +256,15 @@ class TimeWithZoneTest < Test::Unit::TestCase
|
||||
twz2 = ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 2), ActiveSupport::TimeZone['UTC'] )
|
||||
assert_equal 86_400.0, twz2 - twz1
|
||||
end
|
||||
|
||||
def test_minus_with_datetime
|
||||
assert_equal 86_400.0, ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 2), ActiveSupport::TimeZone['UTC'] ) - DateTime.civil(2000, 1, 1)
|
||||
end
|
||||
|
||||
def test_minus_with_wrapped_datetime
|
||||
assert_equal 86_400.0, ActiveSupport::TimeWithZone.new( DateTime.civil(2000, 1, 2), ActiveSupport::TimeZone['UTC'] ) - Time.utc(2000, 1, 1)
|
||||
assert_equal 86_400.0, ActiveSupport::TimeWithZone.new( DateTime.civil(2000, 1, 2), ActiveSupport::TimeZone['UTC'] ) - DateTime.civil(2000, 1, 1)
|
||||
end
|
||||
|
||||
def test_plus_and_minus_enforce_spring_dst_rules
|
||||
silence_warnings do # silence warnings raised by tzinfo gem
|
||||
|
||||
Reference in New Issue
Block a user