aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Gemfile1
-rw-r--r--actionpack/actionpack.gemspec4
-rw-r--r--actionpack/lib/action_controller/metal/params_wrapper.rb34
-rw-r--r--actionpack/lib/action_dispatch/middleware/cookies.rb6
-rw-r--r--actionpack/test/controller/log_subscriber_test.rb6
-rw-r--r--actionpack/test/controller/params_wrapper_test.rb12
-rw-r--r--actionpack/test/dispatch/cookies_test.rb12
-rw-r--r--activemodel/lib/active_model/naming.rb5
-rw-r--r--activemodel/test/cases/naming_test.rb39
-rw-r--r--activerecord/lib/active_record/associations.rb17
-rw-r--r--activerecord/lib/active_record/associations/collection_proxy.rb24
-rw-r--r--activerecord/lib/active_record/base.rb2
-rw-r--r--activerecord/lib/active_record/connection_adapters/column.rb2
-rw-r--r--activerecord/lib/active_record/relation/finder_methods.rb2
-rw-r--r--activerecord/lib/active_record/serialization.rb2
-rw-r--r--activerecord/lib/rails/generators/active_record/model/templates/migration.rb2
-rw-r--r--activerecord/test/cases/associations_test.rb12
-rw-r--r--railties/lib/rails/application.rb3
-rw-r--r--railties/lib/rails/engine.rb12
-rw-r--r--railties/lib/rails/rack.rb8
-rw-r--r--railties/lib/rails/rack/content_length.rb38
-rw-r--r--railties/lib/rails/rack/static.rb5
-rw-r--r--railties/test/application/middleware_test.rb11
23 files changed, 190 insertions, 69 deletions
diff --git a/Gemfile b/Gemfile
index e2128abd9f..e3cfd12133 100644
--- a/Gemfile
+++ b/Gemfile
@@ -11,7 +11,6 @@ end
gem "coffee-script"
gem "sass"
gem "uglifier", :git => "git://github.com/lautis/uglifier.git"
-gem "rack", :git => "git://github.com/rack/rack.git"
gem "rake", ">= 0.8.7"
gem "mocha", ">= 0.9.8"
diff --git a/actionpack/actionpack.gemspec b/actionpack/actionpack.gemspec
index 0b4e7027ed..45958ec75a 100644
--- a/actionpack/actionpack.gemspec
+++ b/actionpack/actionpack.gemspec
@@ -22,10 +22,10 @@ Gem::Specification.new do |s|
s.add_dependency('rack-cache', '~> 1.0.1')
s.add_dependency('builder', '~> 3.0.0')
s.add_dependency('i18n', '~> 0.6.0beta1')
- s.add_dependency('rack', '~> 1.3.0.beta')
+ s.add_dependency('rack', '~> 1.3.0.beta2')
s.add_dependency('rack-test', '~> 0.6.0')
s.add_dependency('rack-mount', '~> 0.8.1')
- s.add_dependency('sprockets', '~> 2.0.0.beta.3')
+ s.add_dependency('sprockets', '~> 2.0.0.beta.5')
s.add_dependency('tzinfo', '~> 0.3.27')
s.add_dependency('erubis', '~> 2.7.0')
end
diff --git a/actionpack/lib/action_controller/metal/params_wrapper.rb b/actionpack/lib/action_controller/metal/params_wrapper.rb
index 93241fc056..5500f88930 100644
--- a/actionpack/lib/action_controller/metal/params_wrapper.rb
+++ b/actionpack/lib/action_controller/metal/params_wrapper.rb
@@ -37,11 +37,11 @@ module ActionController
# {"name" => "Konata", "user" => {"name" => "Konata"}}
#
# You can also specify the key in which the parameters should be wrapped to,
- # and also the list of attributes it should wrap by using either +:only+ or
- # +:except+ options like this:
+ # and also the list of attributes it should wrap by using either +:include+ or
+ # +:exclude+ options like this:
#
# class UsersController < ApplicationController
- # wrap_parameters :person, :only => [:username, :password]
+ # wrap_parameters :person, :include => [:username, :password]
# end
#
# If you're going to pass the parameters to an +ActiveModel+ object (such as
@@ -53,7 +53,7 @@ module ActionController
# wrap_parameters Person
# end
#
- # You still could pass +:only+ and +:except+ to set the list of attributes
+ # You still could pass +:include+ and +:exclude+ to set the list of attributes
# you want to wrap.
#
# By default, if you don't specify the key in which the parameters would be
@@ -73,7 +73,7 @@ module ActionController
included do
class_attribute :_wrapper_options
- self._wrapper_options = {:format => []}
+ self._wrapper_options = { :format => [] }
end
module ClassMethods
@@ -91,7 +91,7 @@ module ActionController
# # wraps parameters by determine the wrapper key from Person class
# (+person+, in this case) and the list of attribute names
#
- # wrap_parameters :only => [:username, :title]
+ # wrap_parameters :include => [:username, :title]
# # wraps only +:username+ and +:title+ attributes from parameters.
#
# wrap_parameters false
@@ -100,9 +100,9 @@ module ActionController
# ==== Options
# * <tt>:format</tt> - The list of formats in which the parameters wrapper
# will be enabled.
- # * <tt>:only</tt> - The list of attribute names which parameters wrapper
+ # * <tt>:include</tt> - The list of attribute names which parameters wrapper
# will wrap into a nested hash.
- # * <tt>:except</tt> - The list of attribute names which parameters wrapper
+ # * <tt>:exclude</tt> - The list of attribute names which parameters wrapper
# will exclude from a nested hash.
def wrap_parameters(name_or_model_or_options, options = {})
model = nil
@@ -164,10 +164,10 @@ module ActionController
def _set_wrapper_defaults(options, model=nil)
options = options.dup
- unless options[:only] || options[:except]
+ unless options[:include] || options[:exclude]
model ||= _default_wrap_model
if model.respond_to?(:attribute_names) && model.attribute_names.present?
- options[:only] = model.attribute_names
+ options[:include] = model.attribute_names
end
end
@@ -177,9 +177,9 @@ module ActionController
controller_name.singularize
end
- options[:only] = Array.wrap(options[:only]).collect(&:to_s) if options[:only]
- options[:except] = Array.wrap(options[:except]).collect(&:to_s) if options[:except]
- options[:format] = Array.wrap(options[:format])
+ options[:include] = Array.wrap(options[:include]).collect(&:to_s) if options[:include]
+ options[:exclude] = Array.wrap(options[:exclude]).collect(&:to_s) if options[:exclude]
+ options[:format] = Array.wrap(options[:format])
self._wrapper_options = options
end
@@ -216,11 +216,11 @@ module ActionController
# Returns the list of parameters which will be selected for wrapped.
def _wrap_parameters(parameters)
- value = if only = _wrapper_options[:only]
- parameters.slice(*only)
+ value = if include_only = _wrapper_options[:include]
+ parameters.slice(*include_only)
else
- except = _wrapper_options[:except] || []
- parameters.except(*(except + EXCLUDE_PARAMETERS))
+ exclude = _wrapper_options[:exclude] || []
+ parameters.except(*(exclude + EXCLUDE_PARAMETERS))
end
{ _wrapper_key => value }
diff --git a/actionpack/lib/action_dispatch/middleware/cookies.rb b/actionpack/lib/action_dispatch/middleware/cookies.rb
index 24ebb8fed7..0057f64dd3 100644
--- a/actionpack/lib/action_dispatch/middleware/cookies.rb
+++ b/actionpack/lib/action_dispatch/middleware/cookies.rb
@@ -167,8 +167,8 @@ module ActionDispatch
handle_options(options)
- @set_cookies[key] = options
- @delete_cookies.delete(key)
+ @set_cookies[key.to_s] = options
+ @delete_cookies.delete(key.to_s)
value
end
@@ -181,7 +181,7 @@ module ActionDispatch
handle_options(options)
value = @cookies.delete(key.to_s)
- @delete_cookies[key] = options
+ @delete_cookies[key.to_s] = options
value
end
diff --git a/actionpack/test/controller/log_subscriber_test.rb b/actionpack/test/controller/log_subscriber_test.rb
index 5d7a51e902..80c4fa2ee5 100644
--- a/actionpack/test/controller/log_subscriber_test.rb
+++ b/actionpack/test/controller/log_subscriber_test.rb
@@ -4,7 +4,7 @@ require "action_controller/log_subscriber"
module Another
class LogSubscribersController < ActionController::Base
- wrap_parameters :person, :only => :name, :format => :json
+ wrap_parameters :person, :include => :name, :format => :json
def show
render :nothing => true
@@ -34,11 +34,11 @@ module Another
cache_page("Super soaker", "/index.html")
render :nothing => true
end
-
+
def with_exception
raise Exception
end
-
+
end
end
diff --git a/actionpack/test/controller/params_wrapper_test.rb b/actionpack/test/controller/params_wrapper_test.rb
index a50065bcc7..7bef1e8d5d 100644
--- a/actionpack/test/controller/params_wrapper_test.rb
+++ b/actionpack/test/controller/params_wrapper_test.rb
@@ -65,9 +65,9 @@ class ParamsWrapperTest < ActionController::TestCase
end
end
- def test_specify_only_option
+ def test_specify_include_option
with_default_wrapper_options do
- UsersController.wrap_parameters :only => :username
+ UsersController.wrap_parameters :include => :username
@request.env['CONTENT_TYPE'] = 'application/json'
post :parse, { 'username' => 'sikachu', 'title' => 'Developer' }
@@ -75,9 +75,9 @@ class ParamsWrapperTest < ActionController::TestCase
end
end
- def test_specify_except_option
+ def test_specify_exclude_option
with_default_wrapper_options do
- UsersController.wrap_parameters :except => :title
+ UsersController.wrap_parameters :exclude => :title
@request.env['CONTENT_TYPE'] = 'application/json'
post :parse, { 'username' => 'sikachu', 'title' => 'Developer' }
@@ -85,9 +85,9 @@ class ParamsWrapperTest < ActionController::TestCase
end
end
- def test_specify_both_wrapper_name_and_only_option
+ def test_specify_both_wrapper_name_and_include_option
with_default_wrapper_options do
- UsersController.wrap_parameters :person, :only => :username
+ UsersController.wrap_parameters :person, :include => :username
@request.env['CONTENT_TYPE'] = 'application/json'
post :parse, { 'username' => 'sikachu', 'title' => 'Developer' }
diff --git a/actionpack/test/dispatch/cookies_test.rb b/actionpack/test/dispatch/cookies_test.rb
index ebc16694db..e42c39f527 100644
--- a/actionpack/test/dispatch/cookies_test.rb
+++ b/actionpack/test/dispatch/cookies_test.rb
@@ -121,7 +121,7 @@ class CookiesTest < ActionController::TestCase
end
def string_key
- cookies['user_name'] = "david"
+ cookies['user_name'] = "dhh"
head :ok
end
@@ -417,14 +417,18 @@ class CookiesTest < ActionController::TestCase
assert_cookie_header "user_name=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT"
end
+
def test_cookies_hash_is_indifferent_access
- [:symbol_key, :string_key].each do |cookie_key|
- get cookie_key
+ get :symbol_key
assert_equal "david", cookies[:user_name]
assert_equal "david", cookies['user_name']
- end
+ get :string_key
+ assert_equal "dhh", cookies[:user_name]
+ assert_equal "dhh", cookies['user_name']
end
+
+
def test_setting_request_cookies_is_indifferent_access
@request.cookies.clear
@request.cookies[:user_name] = "andrew"
diff --git a/activemodel/lib/active_model/naming.rb b/activemodel/lib/active_model/naming.rb
index 74708692af..4c1a82f413 100644
--- a/activemodel/lib/active_model/naming.rb
+++ b/activemodel/lib/active_model/naming.rb
@@ -7,8 +7,9 @@ module ActiveModel
attr_reader :singular, :plural, :element, :collection, :partial_path, :route_key, :param_key, :i18n_key
alias_method :cache_key, :collection
- def initialize(klass, namespace = nil)
- super(klass.name)
+ def initialize(klass, namespace = nil, name = nil)
+ name ||= klass.name
+ super(name)
@unnamespaced = self.sub(/^#{namespace.name}::/, '') if namespace
@klass = klass
diff --git a/activemodel/test/cases/naming_test.rb b/activemodel/test/cases/naming_test.rb
index a7dde2c433..f814fcc56c 100644
--- a/activemodel/test/cases/naming_test.rb
+++ b/activemodel/test/cases/naming_test.rb
@@ -114,6 +114,44 @@ class NamingWithNamespacedModelInSharedNamespaceTest < ActiveModel::TestCase
end
end
+class NamingWithSuppliedModelNameTest < ActiveModel::TestCase
+ def setup
+ @model_name = ActiveModel::Name.new(Blog::Post, nil, 'Article')
+ end
+
+ def test_singular
+ assert_equal 'article', @model_name.singular
+ end
+
+ def test_plural
+ assert_equal 'articles', @model_name.plural
+ end
+
+ def test_element
+ assert_equal 'article', @model_name.element
+ end
+
+ def test_collection
+ assert_equal 'articles', @model_name.collection
+ end
+
+ def test_partial_path
+ assert_equal 'articles/article', @model_name.partial_path
+ end
+
+ def test_human
+ 'Article'
+ end
+
+ def test_route_key
+ assert_equal 'articles', @model_name.route_key
+ end
+
+ def test_param_key
+ assert_equal 'article', @model_name.param_key
+ end
+end
+
class NamingHelpersTest < Test::Unit::TestCase
def setup
@klass = Contact
@@ -171,4 +209,3 @@ class NamingHelpersTest < Test::Unit::TestCase
ActiveModel::Naming.send(method, *args)
end
end
-
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index 9bc44e5163..4979113b0b 100644
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -33,7 +33,7 @@ module ActiveRecord
class HasManyThroughAssociationPointlessSourceTypeError < ActiveRecordError #:nodoc:
def initialize(owner_class_name, reflection, source_reflection)
- super("Cannot have a has_many :through association '#{owner_class_name}##{reflection.name}' with a :source_type option if the '#{reflection.through_reflection.class_name}##{source_reflection.name}' is not polymorphic. Try removing :source_type on your association.")
+ super("Cannot have a has_many :through association '#{owner_class_name}##{reflection.name}' with a :source_type option if the '#{reflection.through_reflection.class_name}##{source_reflection.name}' is not polymorphic. Try removing :source_type on your association.")
end
end
@@ -48,7 +48,7 @@ module ActiveRecord
through_reflection = reflection.through_reflection
source_reflection_names = reflection.source_reflection_names
source_associations = reflection.through_reflection.klass.reflect_on_all_associations.collect { |a| a.name.inspect }
- super("Could not find the source association(s) #{source_reflection_names.collect{ |a| a.inspect }.to_sentence(:two_words_connector => ' or ', :last_word_connector => ', or ', :locale => :en)} in model #{through_reflection.klass}. Try 'has_many #{reflection.name.inspect}, :through => #{through_reflection.name.inspect}, :source => <name>'. Is it one of #{source_associations.to_sentence(:two_words_connector => ' or ', :last_word_connector => ', or ', :locale => :en)}?")
+ super("Could not find the source association(s) #{source_reflection_names.collect{ |a| a.inspect }.to_sentence(:two_words_connector => ' or ', :last_word_connector => ', or ', :locale => :en)} in model #{through_reflection.klass}. Try 'has_many #{reflection.name.inspect}, :through => #{through_reflection.name.inspect}, :source => <name>'. Is it one of #{source_associations.to_sentence(:two_words_connector => ' or ', :last_word_connector => ', or ', :locale => :en)}?")
end
end
@@ -96,7 +96,7 @@ module ActiveRecord
class ReadOnlyAssociation < ActiveRecordError #:nodoc:
def initialize(reflection)
- super("Can not add to a has_many :through association. Try adding to #{reflection.through_reflection.name.inspect}.")
+ super("Can not add to a has_many :through association. Try adding to #{reflection.through_reflection.name.inspect}.")
end
end
@@ -457,12 +457,13 @@ module ActiveRecord
# has_many :people, :extend => [FindOrCreateByNameExtension, FindRecentExtension]
# end
#
- # Some extensions can only be made to work with knowledge of the association proxy's internals.
- # Extensions can access relevant state using accessors on the association proxy:
+ # Some extensions can only be made to work with knowledge of the association's internals.
+ # Extensions can access relevant state using the following methods (where 'items' is the
+ # name of the association):
#
- # * +proxy_owner+ - Returns the object the association is part of.
- # * +proxy_reflection+ - Returns the reflection object that describes the association.
- # * +proxy_target+ - Returns the associated object for +belongs_to+ and +has_one+, or
+ # * +record.association(:items).owner+ - Returns the object the association is part of.
+ # * +record.association(:items).reflection+ - Returns the reflection object that describes the association.
+ # * +record.association(:items).target+ - Returns the associated object for +belongs_to+ and +has_one+, or
# the collection of associated objects for +has_many+ and +has_and_belongs_to_many+.
#
# === Association Join Models
diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb
index adfc71d435..8415942a1a 100644
--- a/activerecord/lib/active_record/associations/collection_proxy.rb
+++ b/activerecord/lib/active_record/associations/collection_proxy.rb
@@ -123,6 +123,30 @@ module ActiveRecord
method_missing(:new, *args, &block)
end
end
+
+ def proxy_owner
+ ActiveSupport::Deprecation.warn(
+ "Calling record.#{@association.reflection.name}.proxy_owner is deprecated. Please use " \
+ "record.association(:#{@association.reflection.name}).owner instead."
+ )
+ @association.owner
+ end
+
+ def proxy_target
+ ActiveSupport::Deprecation.warn(
+ "Calling record.#{@association.reflection.name}.proxy_target is deprecated. Please use " \
+ "record.association(:#{@association.reflection.name}).target instead."
+ )
+ @association.target
+ end
+
+ def proxy_reflection
+ ActiveSupport::Deprecation.warn(
+ "Calling record.#{@association.reflection.name}.proxy_reflection is deprecated. Please use " \
+ "record.association(:#{@association.reflection.name}).reflection instead."
+ )
+ @association.reflection
+ end
end
end
end
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index cd16b8d3ca..30e2d1a82c 100644
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -2018,7 +2018,7 @@ MSG
def extract_callstack_for_multiparameter_attributes(pairs)
attributes = { }
- for pair in pairs
+ pairs.each do |pair|
multiparameter_name, value = pair
attribute_name = multiparameter_name.split("(").first
attributes[attribute_name] = {} unless attributes.include?(attribute_name)
diff --git a/activerecord/lib/active_record/connection_adapters/column.rb b/activerecord/lib/active_record/connection_adapters/column.rb
index 4e3d8a096f..3eddb69e73 100644
--- a/activerecord/lib/active_record/connection_adapters/column.rb
+++ b/activerecord/lib/active_record/connection_adapters/column.rb
@@ -189,7 +189,7 @@ module ActiveRecord
def new_time(year, mon, mday, hour, min, sec, microsec)
# Treat 0000-00-00 00:00:00 as nil.
- return nil if year.nil? || year == 0
+ return nil if year.nil? || (year == 0 && mon == 0 && mday == 0)
Time.time_with_datetime_fallback(Base.default_timezone, year, mon, mday, hour, min, sec, microsec) rescue nil
end
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb
index 32d1cff6c3..475e4338ca 100644
--- a/activerecord/lib/active_record/relation/finder_methods.rb
+++ b/activerecord/lib/active_record/relation/finder_methods.rb
@@ -226,7 +226,7 @@ module ActiveRecord
end
def apply_join_dependency(relation, join_dependency)
- for association in join_dependency.join_associations
+ join_dependency.join_associations.each do |association|
relation = association.join_relation(relation)
end
diff --git a/activerecord/lib/active_record/serialization.rb b/activerecord/lib/active_record/serialization.rb
index 2bde06f562..be4354ce6a 100644
--- a/activerecord/lib/active_record/serialization.rb
+++ b/activerecord/lib/active_record/serialization.rb
@@ -37,7 +37,7 @@ module ActiveRecord #:nodoc:
include_has_options = include_associations.is_a?(Hash)
associations = include_has_options ? include_associations.keys : Array.wrap(include_associations)
- for association in associations
+ associations.each do |association|
records = case self.class.reflect_on_association(association).macro
when :has_many, :has_and_belongs_to_many
send(association).to_a
diff --git a/activerecord/lib/rails/generators/active_record/model/templates/migration.rb b/activerecord/lib/rails/generators/active_record/model/templates/migration.rb
index 4f81a52fd0..851930344a 100644
--- a/activerecord/lib/rails/generators/active_record/model/templates/migration.rb
+++ b/activerecord/lib/rails/generators/active_record/model/templates/migration.rb
@@ -1,7 +1,7 @@
class <%= migration_class_name %> < ActiveRecord::Migration
def change
create_table :<%= table_name %> do |t|
-<% for attribute in attributes -%>
+<% attributes.each do |attribute| -%>
t.<%= attribute.type %> :<%= attribute.name %>
<% end -%>
<% if options[:timestamps] %>
diff --git a/activerecord/test/cases/associations_test.rb b/activerecord/test/cases/associations_test.rb
index 49d82ba2df..38d439d68a 100644
--- a/activerecord/test/cases/associations_test.rb
+++ b/activerecord/test/cases/associations_test.rb
@@ -203,6 +203,18 @@ class AssociationProxyTest < ActiveRecord::TestCase
assert_equal david.projects, david.projects.reload.reload
end
end
+
+ # Tests that proxy_owner, proxy_target and proxy_reflection are implement as deprecated methods
+ def test_proxy_deprecations
+ david = developers(:david)
+ david.projects.load_target
+
+ [:owner, :target, :reflection].each do |name|
+ assert_deprecated do
+ assert_equal david.association(:projects).send(name), david.projects.send("proxy_#{name}")
+ end
+ end
+ end
end
class OverridingAssociationsTest < ActiveRecord::TestCase
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb
index 1e4d25f18c..816bff29b7 100644
--- a/railties/lib/rails/application.rb
+++ b/railties/lib/rails/application.rb
@@ -141,6 +141,8 @@ module Rails
def default_middleware_stack
ActionDispatch::MiddlewareStack.new.tap do |middleware|
+ middleware.use ::Rails::Rack::ContentLength, config.action_dispatch.x_sendfile_header
+
if rack_cache = config.action_controller.perform_caching && config.action_dispatch.rack_cache
require "action_dispatch/http/rack_cache"
middleware.use ::Rack::Cache, rack_cache
@@ -195,6 +197,7 @@ module Rails
end
def initialize_console(sandbox=false)
+ require "pp"
require "rails/console/app"
require "rails/console/helpers"
end
diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb
index e26f73ed8d..81a0350724 100644
--- a/railties/lib/rails/engine.rb
+++ b/railties/lib/rails/engine.rb
@@ -522,9 +522,15 @@ module Rails
end
initializer :append_assets_path do |app|
- app.config.assets.paths.unshift(*paths["vendor/assets"].existent)
- app.config.assets.paths.unshift(*paths["lib/assets"].existent)
- app.config.assets.paths.unshift(*paths["app/assets"].existent)
+ if app.config.assets.respond_to?(:prepend_path)
+ app.config.assets.prepend_path(*paths["vendor/assets"].existent)
+ app.config.assets.prepend_path(*paths["lib/assets"].existent)
+ app.config.assets.prepend_path(*paths["app/assets"].existent)
+ else
+ app.config.assets.paths.unshift(*paths["vendor/assets"].existent)
+ app.config.assets.paths.unshift(*paths["lib/assets"].existent)
+ app.config.assets.paths.unshift(*paths["app/assets"].existent)
+ end
end
initializer :prepend_helpers_path do |app|
diff --git a/railties/lib/rails/rack.rb b/railties/lib/rails/rack.rb
index 1f20ceae44..d4a41b217e 100644
--- a/railties/lib/rails/rack.rb
+++ b/railties/lib/rails/rack.rb
@@ -1,8 +1,8 @@
module Rails
module Rack
- autoload :Debugger, "rails/rack/debugger"
- autoload :Logger, "rails/rack/logger"
- autoload :LogTailer, "rails/rack/log_tailer"
- autoload :Static, "rails/rack/static"
+ autoload :ContentLength, "rails/rack/content_length"
+ autoload :Debugger, "rails/rack/debugger"
+ autoload :Logger, "rails/rack/logger"
+ autoload :LogTailer, "rails/rack/log_tailer"
end
end
diff --git a/railties/lib/rails/rack/content_length.rb b/railties/lib/rails/rack/content_length.rb
new file mode 100644
index 0000000000..6839af4152
--- /dev/null
+++ b/railties/lib/rails/rack/content_length.rb
@@ -0,0 +1,38 @@
+require 'action_dispatch'
+require 'rack/utils'
+
+module Rails
+ module Rack
+ # Sets the Content-Length header on responses with fixed-length bodies.
+ class ContentLength
+ include ::Rack::Utils
+
+ def initialize(app, sendfile=nil)
+ @app = app
+ @sendfile = sendfile
+ end
+
+ def call(env)
+ status, headers, body = @app.call(env)
+ headers = HeaderHash.new(headers)
+
+ if !STATUS_WITH_NO_ENTITY_BODY.include?(status.to_i) &&
+ !headers['Content-Length'] &&
+ !headers['Transfer-Encoding'] &&
+ !(@sendfile && headers[@sendfile])
+
+ old_body = body
+ body, length = [], 0
+ old_body.each do |part|
+ body << part
+ length += bytesize(part)
+ end
+ old_body.close if old_body.respond_to?(:close)
+ headers['Content-Length'] = length.to_s
+ end
+
+ [status, headers, body]
+ end
+ end
+ end
+end \ No newline at end of file
diff --git a/railties/lib/rails/rack/static.rb b/railties/lib/rails/rack/static.rb
deleted file mode 100644
index ebe8b9e103..0000000000
--- a/railties/lib/rails/rack/static.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-require 'action_dispatch'
-
-module Rails::Rack
- Static = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('Rails::Rack::Static', ActionDispatch::Static)
-end
diff --git a/railties/test/application/middleware_test.rb b/railties/test/application/middleware_test.rb
index 8bfde00af5..ef448f7791 100644
--- a/railties/test/application/middleware_test.rb
+++ b/railties/test/application/middleware_test.rb
@@ -19,6 +19,7 @@ module ApplicationTests
boot!
assert_equal [
+ "Rails::Rack::ContentLength",
"ActionDispatch::Static",
"Rack::Lock",
"ActiveSupport::Cache::Strategy::LocalCache",
@@ -48,7 +49,7 @@ module ApplicationTests
boot!
- assert_equal "Rack::Cache", middleware.first
+ assert_equal "Rack::Cache", middleware.second
end
test "Rack::SSL is present when force_ssl is set" do
@@ -103,7 +104,7 @@ module ApplicationTests
end
test "insert middleware after" do
- add_to_config "config.middleware.insert_after ActionDispatch::Static, Rack::Config"
+ add_to_config "config.middleware.insert_after Rails::Rack::ContentLength, Rack::Config"
boot!
assert_equal "Rack::Config", middleware.second
end
@@ -111,12 +112,12 @@ module ApplicationTests
test "RAILS_CACHE does not respond to middleware" do
add_to_config "config.cache_store = :memory_store"
boot!
- assert_equal "Rack::Runtime", middleware.third
+ assert_equal "Rack::Runtime", middleware.fourth
end
test "RAILS_CACHE does respond to middleware" do
boot!
- assert_equal "Rack::Runtime", middleware.fourth
+ assert_equal "Rack::Runtime", middleware.fifth
end
test "identity map is inserted" do
@@ -126,7 +127,7 @@ module ApplicationTests
end
test "insert middleware before" do
- add_to_config "config.middleware.insert_before ActionDispatch::Static, Rack::Config"
+ add_to_config "config.middleware.insert_before Rails::Rack::ContentLength, Rack::Config"
boot!
assert_equal "Rack::Config", middleware.first
end