diff options
20 files changed, 122 insertions, 38 deletions
@@ -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 08d5d689ae..45958ec75a 100644 --- a/actionpack/actionpack.gemspec +++ b/actionpack/actionpack.gemspec @@ -22,7 +22,7 @@ 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.5') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 3ba6094fbb..c25f8c90bc 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -910,7 +910,7 @@ module ActionDispatch alias :member_name :singular - # Checks for uncountable plurals, and appends "_index" if the plural + # Checks for uncountable plurals, and appends "_index" if the plural # and singular form are the same. def collection_name singular == plural ? "#{plural}_index" : plural @@ -1083,9 +1083,13 @@ module ActionDispatch # Is the same as: # # resources :posts do - # resources :comments + # resources :comments, :except => [:show, :edit, :update, :destroy] # end - # resources :comments + # resources :comments, :only => [:show, :edit, :update, :destroy] + # + # This allows URLs for resources that otherwise would be deeply nested such + # as a comment on a blog post like <tt>/posts/a-long-permalink/comments/1234</tt> + # to be shortened to just <tt>/comments/1234</tt>. # # [:shallow_path] # Prefixes nested shallow routes with the specified path. diff --git a/actionpack/lib/action_view/helpers/asset_paths.rb b/actionpack/lib/action_view/helpers/asset_paths.rb index 958f0e0a10..38810eea2e 100644 --- a/actionpack/lib/action_view/helpers/asset_paths.rb +++ b/actionpack/lib/action_view/helpers/asset_paths.rb @@ -1,5 +1,4 @@ require 'active_support/core_ext/file' -require 'action_view/helpers/asset_paths' module ActionView module Helpers diff --git a/actionpack/lib/action_view/template/handlers/erb.rb b/actionpack/lib/action_view/template/handlers/erb.rb index 7e9e4e518a..a1e3fd7768 100644 --- a/actionpack/lib/action_view/template/handlers/erb.rb +++ b/actionpack/lib/action_view/template/handlers/erb.rb @@ -1,5 +1,4 @@ require 'active_support/core_ext/class/attribute_accessors' -require 'action_view/template' require 'action_view/template/handler' require 'erubis' 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 a017c1aa1e..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 diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 1ece79adc0..92e525a361 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/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/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index 65d285249b..0c272fa093 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -3,7 +3,6 @@ require 'active_support/core_ext/class/attribute_accessors' require 'active_support/core_ext/class/attribute' require 'active_support/core_ext/hash/indifferent_access' require 'active_support/core_ext/kernel/reporting' -require 'active_support/core_ext/module/attr_accessor_with_default' require 'active_support/core_ext/module/delegation' require 'active_support/core_ext/module/aliasing' require 'active_support/core_ext/object/blank' @@ -565,10 +564,23 @@ module ActiveResource @headers ||= {} end - attr_accessor_with_default(:element_name) { model_name.element } #:nodoc: - attr_accessor_with_default(:collection_name) { ActiveSupport::Inflector.pluralize(element_name) } #:nodoc: + attr_writer :element_name - attr_accessor_with_default(:primary_key, 'id') #:nodoc: + def element_name + @element_name ||= model_name.element + end + + attr_writer :collection_name + + def collection_name + @collection_name ||= ActiveSupport::Inflector.pluralize(element_name) + end + + attr_writer :primary_key + + def primary_key + @primary_key ||= 'id' + end # Gets the \prefix for a resource's nested URL (e.g., <tt>prefix/collectionname/1.json</tt>) # This method is regenerated at runtime based on what the \prefix is set to. diff --git a/activesupport/lib/active_support/buffered_logger.rb b/activesupport/lib/active_support/buffered_logger.rb index b937d4c50d..2668087f57 100644 --- a/activesupport/lib/active_support/buffered_logger.rb +++ b/activesupport/lib/active_support/buffered_logger.rb @@ -56,9 +56,9 @@ module ActiveSupport end def open_log(log, mode) - open(log, mode).tap do |log| - log.set_encoding(Encoding::BINARY) if log.respond_to?(:set_encoding) - log.sync = true + open(log, mode).tap do |open_log| + open_log.set_encoding(Encoding::BINARY) if open_log.respond_to?(:set_encoding) + open_log.sync = true end end diff --git a/activesupport/test/deprecation_test.rb b/activesupport/test/deprecation_test.rb index cad0810241..d77a62f108 100644 --- a/activesupport/test/deprecation_test.rb +++ b/activesupport/test/deprecation_test.rb @@ -62,7 +62,7 @@ class DeprecationTest < ActiveSupport::TestCase end def test_deprecate_class_method - assert_deprecated(/none is deprecated.*test_deprecate_class_method/) do + assert_deprecated(/none is deprecated/) do assert_equal 1, @dtc.none end diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 88ef95334f..816bff29b7 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -141,7 +141,7 @@ module Rails def default_middleware_stack ActionDispatch::MiddlewareStack.new.tap do |middleware| - middleware.use ::Rack::ContentLength, config.action_dispatch.x_sendfile_header + 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" 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 6f14200a14..ef448f7791 100644 --- a/railties/test/application/middleware_test.rb +++ b/railties/test/application/middleware_test.rb @@ -19,7 +19,7 @@ module ApplicationTests boot! assert_equal [ - "Rack::ContentLength", + "Rails::Rack::ContentLength", "ActionDispatch::Static", "Rack::Lock", "ActiveSupport::Cache::Strategy::LocalCache", @@ -104,7 +104,7 @@ module ApplicationTests end test "insert middleware after" do - add_to_config "config.middleware.insert_after Rack::ContentLength, Rack::Config" + add_to_config "config.middleware.insert_after Rails::Rack::ContentLength, Rack::Config" boot! assert_equal "Rack::Config", middleware.second end @@ -127,7 +127,7 @@ module ApplicationTests end test "insert middleware before" do - add_to_config "config.middleware.insert_before Rack::ContentLength, Rack::Config" + add_to_config "config.middleware.insert_before Rails::Rack::ContentLength, Rack::Config" boot! assert_equal "Rack::Config", middleware.first end |