aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Gemfile1
-rw-r--r--actionpack/actionpack.gemspec2
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb10
-rw-r--r--actionpack/lib/action_view/helpers/asset_paths.rb1
-rw-r--r--actionpack/lib/action_view/template/handlers/erb.rb1
-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.rb6
-rw-r--r--activerecord/lib/active_record/associations/alias_tracker.rb4
-rw-r--r--activerecord/lib/active_record/associations/join_helper.rb2
-rw-r--r--activerecord/lib/active_record/base.rb4
-rw-r--r--activerecord/test/cases/associations/join_model_test.rb5
-rw-r--r--activerecord/test/cases/base_test.rb9
-rw-r--r--activerecord/test/models/aircraft.rb1
-rw-r--r--activeresource/lib/active_resource/base.rb20
-rw-r--r--activesupport/lib/active_support/buffered_logger.rb6
-rw-r--r--activesupport/test/deprecation_test.rb2
-rw-r--r--railties/lib/rails/application.rb2
-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.rb6
22 files changed, 134 insertions, 43 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 907968b44f..02a65bf468 100644
--- a/actionpack/actionpack.gemspec
+++ b/actionpack/actionpack.gemspec
@@ -21,7 +21,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/associations/alias_tracker.rb b/activerecord/lib/active_record/associations/alias_tracker.rb
index 44e2ee141e..bd98cf2f46 100644
--- a/activerecord/lib/active_record/associations/alias_tracker.rb
+++ b/activerecord/lib/active_record/associations/alias_tracker.rb
@@ -49,8 +49,8 @@ module ActiveRecord
end
end
- def pluralize(table_name)
- ActiveRecord::Base.pluralize_table_names ? table_name.to_s.pluralize : table_name.to_s
+ def pluralize(table_name, base)
+ base.pluralize_table_names ? table_name.to_s.pluralize : table_name.to_s
end
private
diff --git a/activerecord/lib/active_record/associations/join_helper.rb b/activerecord/lib/active_record/associations/join_helper.rb
index eae546e76e..87e33891a5 100644
--- a/activerecord/lib/active_record/associations/join_helper.rb
+++ b/activerecord/lib/active_record/associations/join_helper.rb
@@ -32,7 +32,7 @@ module ActiveRecord
end
def table_alias_for(reflection, join = false)
- name = alias_tracker.pluralize(reflection.name)
+ name = alias_tracker.pluralize(reflection.name, reflection.active_record)
name << "_#{alias_suffix}"
name << "_join" if join
name
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 30e2d1a82c..92e525a361 100644
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -393,8 +393,8 @@ module ActiveRecord #:nodoc:
# Indicates whether table names should be the pluralized versions of the corresponding class names.
# If true, the default table name for a Product class will be +products+. If false, it would just be +product+.
# See table_name for the full rules on table/class naming. This is true, by default.
- cattr_accessor :pluralize_table_names, :instance_writer => false
- @@pluralize_table_names = true
+ class_attribute :pluralize_table_names, :instance_writer => false
+ self.pluralize_table_names = true
##
# :singleton-method:
diff --git a/activerecord/test/cases/associations/join_model_test.rb b/activerecord/test/cases/associations/join_model_test.rb
index 8e23ab78be..b59ce4efeb 100644
--- a/activerecord/test/cases/associations/join_model_test.rb
+++ b/activerecord/test/cases/associations/join_model_test.rb
@@ -708,12 +708,9 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase
end
def test_has_many_with_pluralize_table_names_false
- engine = Engine.create(:car_id => 1)
- Aircraft.pluralize_table_names = false
+ engine = Engine.create!(:car_id => 1)
aircraft = Aircraft.create!(:name => "Airbus 380", :id => 1)
assert_equal aircraft.engines, [engine]
- ensure
- ActiveRecord::Base.pluralize_table_names = true
end
private
diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb
index bfb66f07da..87ce537e0e 100644
--- a/activerecord/test/cases/base_test.rb
+++ b/activerecord/test/cases/base_test.rb
@@ -367,6 +367,15 @@ class BasicsTest < ActiveRecord::TestCase
GUESSED_CLASSES.each(&:reset_table_name)
end
+ def test_singular_table_name_guesses_for_individual_table
+ CreditCard.pluralize_table_names = false
+ CreditCard.reset_table_name
+ assert_equal "credit_card", CreditCard.table_name
+ assert_equal "categories", Category.table_name
+ ensure
+ CreditCard.pluralize_table_names = true
+ CreditCard.reset_table_name
+ end
if current_adapter?(:MysqlAdapter) or current_adapter?(:Mysql2Adapter)
def test_update_all_with_order_and_limit
diff --git a/activerecord/test/models/aircraft.rb b/activerecord/test/models/aircraft.rb
index 0c47aab539..1f35ef45da 100644
--- a/activerecord/test/models/aircraft.rb
+++ b/activerecord/test/models/aircraft.rb
@@ -1,3 +1,4 @@
class Aircraft < ActiveRecord::Base
+ self.pluralize_table_names = false
has_many :engines, :foreign_key => "car_id"
end
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