Permalink
Browse files

Cherry-pick core extensions

  • Loading branch information...
1 parent fa5da8a commit e8550ee0329586b32de425e905c7af7e65bc78a8 @jeremy jeremy committed May 13, 2009
Showing with 168 additions and 83 deletions.
  1. +1 −1 Rakefile
  2. +6 −0 actionmailer/Rakefile
  3. +1 −0 actionmailer/lib/action_mailer/vendor/tmail.rb
  4. +3 −10 actionpack/lib/action_controller.rb
  5. +2 −0 actionpack/lib/action_controller/base/base.rb
  6. +1 −1 actionpack/lib/action_controller/base/chained/benchmarking.rb
  7. +4 −2 actionpack/lib/action_controller/base/http_authentication.rb
  8. +4 −0 actionpack/lib/action_controller/base/layout.rb
  9. +2 −0 actionpack/lib/action_controller/record_identifier.rb
  10. +2 −0 actionpack/lib/action_controller/routing/builder.rb
  11. +5 −3 actionpack/lib/action_controller/routing/route.rb
  12. +1 −0 actionpack/lib/action_controller/testing/process.rb
  13. +3 −10 actionpack/lib/action_dispatch.rb
  14. +1 −0 actionpack/lib/action_dispatch/http/mime_type.rb
  15. +1 −0 actionpack/lib/action_dispatch/http/request.rb
  16. +1 −0 actionpack/lib/action_dispatch/http/response.rb
  17. +3 −10 actionpack/lib/action_view.rb
  18. +3 −0 actionpack/lib/action_view/base.rb
  19. +5 −4 actionpack/lib/action_view/helpers/form_helper.rb
  20. +1 −0 actionpack/lib/action_view/template/handlers/erb.rb
  21. +2 −2 actionpack/test/abstract_controller/test_helper.rb
  22. +1 −2 actionpack/test/abstract_unit2.rb
  23. +1 −0 actionpack/test/controller/addresses_render_test.rb
  24. +1 −0 actionpack/test/controller/base_test.rb
  25. +1 −0 actionpack/test/controller/capture_test.rb
  26. +1 −0 actionpack/test/controller/helper_test.rb
  27. +6 −0 activemodel/Rakefile
  28. +1 −0 activemodel/test/state_machine/event_test.rb
  29. +1 −0 activemodel/test/state_machine/state_transition_test.rb
  30. +3 −0 activerecord/Rakefile
  31. +0 −1 activerecord/lib/active_record.rb
  32. +2 −0 activerecord/lib/active_record/associations.rb
  33. +2 −0 activerecord/lib/active_record/attribute_methods.rb
  34. +15 −6 activerecord/lib/active_record/base.rb
  35. +1 −0 activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
  36. +2 −0 activerecord/lib/active_record/connection_adapters/abstract/quoting.rb
  37. +2 −0 activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
  38. +1 −0 activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
  39. +1 −0 activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
  40. +3 −3 activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
  41. +1 −0 activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
  42. +3 −1 activerecord/lib/active_record/dirty.rb
  43. +1 −0 activerecord/lib/active_record/fixtures.rb
  44. +5 −5 activerecord/lib/active_record/migration.rb
  45. +3 −0 activerecord/lib/active_record/named_scope.rb
  46. +3 −0 activerecord/lib/active_record/nested_attributes.rb
  47. +2 −2 activerecord/lib/active_record/schema_dumper.rb
  48. +9 −8 activerecord/lib/active_record/serialization.rb
  49. +4 −1 activerecord/lib/active_record/serializers/xml_serializer.rb
  50. +2 −3 activerecord/lib/active_record/validations.rb
  51. +1 −0 activerecord/test/cases/aggregations_test.rb
  52. +1 −0 activerecord/test/cases/associations/eager_load_nested_include_test.rb
  53. +1 −0 activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
  54. +1 −0 activerecord/test/cases/base_test.rb
  55. +3 −2 activerecord/test/cases/finder_test.rb
  56. +5 −0 activerecord/test/cases/helper.rb
  57. +2 −1 activerecord/test/cases/named_scope_test.rb
  58. +1 −0 activerecord/test/cases/nested_attributes_test.rb
  59. +2 −0 activerecord/test/models/company_in_module.rb
  60. +7 −0 activeresource/Rakefile
  61. +3 −1 activeresource/lib/active_resource/base.rb
  62. +1 −0 activeresource/test/base/custom_methods_test.rb
  63. +1 −0 activeresource/test/base/load_test.rb
  64. +1 −0 activeresource/test/base_test.rb
  65. +1 −1 activesupport/Rakefile
  66. +3 −0 activesupport/lib/active_support/core_ext/object/conversions.rb
  67. +1 −0 railties/Rakefile
  68. +1 −1 railties/lib/initializer.rb
  69. +2 −0 railties/lib/rails/plugin.rb
  70. +0 −1 railties/test/abstract_unit.rb
  71. +0 −1 railties/test/plugin_test_helper.rb
View
@@ -12,7 +12,7 @@ end
desc 'Run all tests by default'
task :default => :test
-%w(test rdoc pgem package release).each do |task_name|
+%w(test isolated_test rdoc pgem package release).each do |task_name|
desc "Run #{task_name} task for all projects"
task task_name do
PROJECTS.each do |project|
View
@@ -28,6 +28,12 @@ Rake::TestTask.new { |t|
t.warning = false
}
+task :isolated_test do
+ ruby = File.join(*RbConfig::CONFIG.values_at('bindir', 'RUBY_INSTALL_NAME'))
+ Dir.glob("test/*_test.rb").all? do |file|
+ system(ruby, '-Ilib:test', file)
+ end or raise "Failures"
+end
# Generate the RDoc documentation
Rake::RDocTask.new { |rdoc|
@@ -12,6 +12,7 @@ module TMail
require 'tmail'
+require 'active_support/core_ext/kernel/reporting'
silence_warnings do
TMail::Encoder.const_set("MAX_LINE_LEN", 200)
end
@@ -21,16 +21,9 @@
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#++
-begin
- require 'active_support'
-rescue LoadError
- activesupport_path = "#{File.dirname(__FILE__)}/../../activesupport/lib"
- if File.directory?(activesupport_path)
- $:.unshift activesupport_path
- require 'active_support'
- end
-end
-require 'active_support/core/all'
+activesupport_path = "#{File.dirname(__FILE__)}/../../activesupport/lib"
+$:.unshift activesupport_path if File.directory?(activesupport_path)
+require 'active_support'
require File.join(File.dirname(__FILE__), "action_pack")
@@ -1,5 +1,7 @@
require 'action_controller/deprecated'
require 'set'
+require 'active_support/core_ext/class/inheritable_attributes'
+require 'active_support/core_ext/module/attr_internal'
module ActionController #:nodoc:
class ActionControllerError < StandardError #:nodoc:
@@ -1,4 +1,4 @@
-require 'benchmark'
+require 'active_support/core_ext/benchmark'
module ActionController #:nodoc:
# The benchmarking module times the performance of actions and reports to the logger. If the Active Record
@@ -1,3 +1,5 @@
+require 'active_support/base64'
+
module ActionController
module HttpAuthentication
# Makes it dead easy to do HTTP Basic authentication.
@@ -276,7 +278,7 @@ def nonce(time = Time.now)
t = time.to_i
hashed = [t, secret_key]
digest = ::Digest::MD5.hexdigest(hashed.join(":"))
- Base64.encode64("#{t}:#{digest}").gsub("\n", '')
+ ActiveSupport::Base64.encode64("#{t}:#{digest}").gsub("\n", '')
end
# Might want a shorter timeout depending on whether the request
@@ -285,7 +287,7 @@ def nonce(time = Time.now)
# allow a user to use new nonce without prompting user again for their
# username and password.
def validate_nonce(request, value, seconds_to_timeout=5*60)
- t = Base64.decode64(value).split(":").first.to_i
+ t = ActiveSupport::Base64.decode64(value).split(":").first.to_i
nonce(t) == value && (t - Time.now.to_i).abs <= seconds_to_timeout
end
@@ -1,3 +1,7 @@
+require 'active_support/core_ext/enumerable'
+require 'active_support/core_ext/class/delegating_attributes'
+require 'active_support/core_ext/class/inheritable_attributes'
+
module ActionController #:nodoc:
module Layout #:nodoc:
def self.included(base)
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/module'
+
module ActionController
# The record identifier encapsulates a number of naming conventions for dealing with records, like Active Records or
# Active Resources or pretty much any other model type that has an id. These patterns are then used to try elevate
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/hash/except'
+
module ActionController
module Routing
class RouteBuilder #:nodoc:
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/object/misc'
+
module ActionController
module Routing
class Route #:nodoc:
@@ -65,7 +67,7 @@ def build_query_string(hash, only_keys = nil)
# map.connect '/page/:id', :controller => 'pages', :action => 'show', :id => /\d+/
#
def parameter_shell
- @parameter_shell ||= returning({}) do |shell|
+ @parameter_shell ||= {}.tap do |shell|
requirements.each do |key, requirement|
shell[key] = requirement unless requirement.is_a? Regexp
end
@@ -76,7 +78,7 @@ def parameter_shell
# includes keys that appear inside the path, and keys that have requirements
# placed upon them.
def significant_keys
- @significant_keys ||= returning([]) do |sk|
+ @significant_keys ||= [].tap do |sk|
segments.each { |segment| sk << segment.key if segment.respond_to? :key }
sk.concat requirements.keys
sk.uniq!
@@ -86,7 +88,7 @@ def significant_keys
# Return a hash of key/value pairs representing the keys in the route that
# have defaults, or which are specified by non-regexp requirements.
def defaults
- @defaults ||= returning({}) do |hash|
+ @defaults ||= {}.tap do |hash|
segments.each do |segment|
next unless segment.respond_to? :default
hash[segment.key] = segment.default unless segment.default.nil?
@@ -1,4 +1,5 @@
require 'rack/session/abstract/id'
+require 'active_support/core_ext/object/conversions'
module ActionController #:nodoc:
class TestRequest < ActionDispatch::TestRequest #:nodoc:
@@ -21,16 +21,9 @@
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#++
-begin
- require 'active_support'
-rescue LoadError
- activesupport_path = "#{File.dirname(__FILE__)}/../../activesupport/lib"
- if File.directory?(activesupport_path)
- $:.unshift activesupport_path
- require 'active_support'
- end
-end
-require 'active_support/core/all'
+activesupport_path = "#{File.dirname(__FILE__)}/../../activesupport/lib"
+$:.unshift activesupport_path if File.directory?(activesupport_path)
+require 'active_support'
begin
gem 'rack', '~> 1.1.pre'
@@ -1,4 +1,5 @@
require 'set'
+require 'active_support/core_ext/class/attribute_accessors'
module Mime
SET = []
@@ -3,6 +3,7 @@
require 'strscan'
require 'active_support/memoizable'
+require 'active_support/core_ext/hash/indifferent_access'
module ActionDispatch
class Request < Rack::Request
@@ -1,4 +1,5 @@
require 'digest/md5'
+require 'active_support/core_ext/module/delegation'
module ActionDispatch # :nodoc:
# Represents an HTTP response generated by a controller action. One can use
@@ -21,16 +21,9 @@
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#++
-begin
- require 'active_support'
-rescue LoadError
- activesupport_path = "#{File.dirname(__FILE__)}/../../activesupport/lib"
- if File.directory?(activesupport_path)
- $:.unshift activesupport_path
- require 'active_support'
- end
-end
-require 'active_support/core/all'
+activesupport_path = "#{File.dirname(__FILE__)}/../../activesupport/lib"
+$:.unshift activesupport_path if File.directory?(activesupport_path)
+require 'active_support'
require File.join(File.dirname(__FILE__), "action_pack")
@@ -1,3 +1,6 @@
+require 'active_support/core_ext/module/attr_internal'
+require 'active_support/core_ext/module/delegation'
+
module ActionView #:nodoc:
class ActionViewError < StandardError #:nodoc:
end
@@ -2,6 +2,7 @@
require 'action_view/helpers/date_helper'
require 'action_view/helpers/tag_helper'
require 'action_view/helpers/form_tag_helper'
+require 'active_support/core_ext/class/inheritable_attributes'
module ActionView
module Helpers
@@ -1039,8 +1040,8 @@ def nested_child_index
end
end
- class Base
- cattr_accessor :default_form_builder
- self.default_form_builder = ::ActionView::Helpers::FormBuilder
+ class << Base
+ attr_accessor :default_form_builder
end
-end
+ Base.default_form_builder = ::ActionView::Helpers::FormBuilder
+end
@@ -1,4 +1,5 @@
require 'erb'
+require 'active_support/core_ext/class/attribute_accessors'
module ActionView
module TemplateHandlers
@@ -4,7 +4,7 @@
require 'rubygems'
require 'test/unit'
-require 'active_support/core/all'
+require 'active_support'
require 'active_support/test_case'
require 'action_controller/abstract'
require 'action_view'
@@ -18,4 +18,4 @@
Debugger.start
rescue LoadError
# Debugging disabled. `gem install ruby-debug` to enable.
-end
+end
@@ -5,7 +5,6 @@
require 'test/unit'
require 'active_support'
-require 'active_support/core/all'
require 'active_support/test_case'
require 'action_controller/abstract'
require 'action_controller/new_base'
@@ -129,4 +128,4 @@ def assert_template(options = {}, message = nil)
end
end
end
-end
+end
@@ -1,4 +1,5 @@
require 'abstract_unit'
+require 'logger'
class Address
def Address.count(conditions = nil, join = nil)
@@ -1,4 +1,5 @@
require 'abstract_unit'
+require 'logger'
require 'pp' # require 'pp' early to prevent hidden_methods from not picking up the pretty-print methods until too late
# Provide some controller to run the tests on.
@@ -1,4 +1,5 @@
require 'abstract_unit'
+require 'logger'
class CaptureController < ActionController::Base
def self.controller_name; "test"; end
@@ -1,4 +1,5 @@
require 'abstract_unit'
+require 'active_support/core_ext/kernel/reporting'
ActionController::Base.helpers_dir = File.dirname(__FILE__) + '/../fixtures/helpers'
View
@@ -11,6 +11,12 @@ Rake::TestTask.new do |t|
t.verbose = true
t.warning = true
end
+task :isolated_test do
+ ruby = File.join(*RbConfig::CONFIG.values_at('bindir', 'RUBY_INSTALL_NAME'))
+ Dir.glob("test/**/*_test.rb").all? do |file|
+ system(ruby, '-Ilib:test', file)
+ end or raise "Failures"
+end
# Generate the RDoc documentation
Rake::RDocTask.new do |rdoc|
@@ -1,4 +1,5 @@
require 'test_helper'
+require 'active_model/state_machine/event'
class EventTest < ActiveModel::TestCase
def setup
@@ -1,4 +1,5 @@
require 'test_helper'
+require 'active_model/state_machine/state_transition'
class StateTransitionTest < ActiveModel::TestCase
test 'should set from, to, and opts attr readers' do
View
@@ -32,6 +32,9 @@ desc 'Run mysql, sqlite, and postgresql tests'
task :test => defined?(JRUBY_VERSION) ?
%w(test_jdbcmysql test_jdbcsqlite3 test_jdbcpostgresql) :
%w(test_mysql test_sqlite3 test_postgresql)
+task :isolated_test => defined?(JRUBY_VERSION) ?
+ %w(isolated_test_jdbcmysql isolated_test_jdbcsqlite3 isolated_test_jdbcpostgresql) :
+ %w(isolated_test_mysql isolated_test_sqlite3 isolated_test_postgresql)
%w( mysql postgresql sqlite sqlite3 firebird db2 oracle sybase openbase frontbase jdbcmysql jdbcpostgresql jdbcsqlite3 jdbcderby jdbch2 jdbchsqldb ).each do |adapter|
Rake::TestTask.new("test_#{adapter}") { |t|
@@ -24,7 +24,6 @@
activesupport_path = "#{File.dirname(__FILE__)}/../../activesupport/lib"
$:.unshift(activesupport_path) if File.directory?(activesupport_path)
require 'active_support'
-require 'active_support/core/all'
module ActiveRecord
# TODO: Review explicit loads to see if they will automatically be handled by the initilizer.
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/module/delegation'
+
module ActiveRecord
class InverseOfAssociationNotFoundError < ActiveRecordError #:nodoc:
def initialize(reflection)
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/enumerable'
+
module ActiveRecord
module AttributeMethods #:nodoc:
extend ActiveSupport::DependencyModule
@@ -1,6 +1,15 @@
require 'yaml'
require 'set'
require 'active_support/dependencies'
+require 'active_support/core_ext/class/attribute_accessors'
+require 'active_support/core_ext/class/delegating_attributes'
+require 'active_support/core_ext/class/inheritable_attributes'
+require 'active_support/core_ext/array/extract_options'
+require 'active_support/core_ext/hash/deep_merge'
+require 'active_support/core_ext/hash/indifferent_access'
+require 'active_support/core_ext/hash/slice'
+require 'active_support/core_ext/string/behavior'
+require 'active_support/core/time'
module ActiveRecord #:nodoc:
# Generic Active Record exception class.
@@ -1888,7 +1897,7 @@ def self.#{method_id}(*args)
else
find(:#{finder}, options.merge(finder_options))
end
- #{'result || raise(RecordNotFound, "Couldn\'t find #{name} with #{attributes.to_a.collect {|pair| "#{pair.first} = #{pair.second}"}.join(\', \')}")' if bang}
+ #{'result || raise(RecordNotFound, "Couldn\'t find #{name} with #{attributes.to_a.collect { |pair| pair.join(\' = \') }.join(\', \')}")' if bang}
end
}, __FILE__, __LINE__
send(method_id, *arguments)
@@ -2610,11 +2619,11 @@ def clone
# Note: The new instance will share a link to the same attributes as the original class. So any change to the attributes in either
# instance will affect the other.
def becomes(klass)
- returning klass.new do |became|
- became.instance_variable_set("@attributes", @attributes)
- became.instance_variable_set("@attributes_cache", @attributes_cache)
- became.instance_variable_set("@new_record", new_record?)
- end
+ became = klass.new
+ became.instance_variable_set("@attributes", @attributes)
+ became.instance_variable_set("@attributes_cache", @attributes_cache)
+ became.instance_variable_set("@new_record", new_record?)
+ became
end
# Updates a single attribute and saves the record without going through the normal validation procedure.
Oops, something went wrong.

0 comments on commit e8550ee

Please sign in to comment.