Skip to content
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
2 Rakefile
@@ -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
6 actionmailer/Rakefile
@@ -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|
View
1 actionmailer/lib/action_mailer/vendor/tmail.rb
@@ -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
View
13 actionpack/lib/action_controller.rb
@@ -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")
View
2 actionpack/lib/action_controller/base/base.rb
@@ -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:
View
2 actionpack/lib/action_controller/base/chained/benchmarking.rb
@@ -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
View
6 actionpack/lib/action_controller/base/http_authentication.rb
@@ -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
View
4 actionpack/lib/action_controller/base/layout.rb
@@ -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)
View
2 actionpack/lib/action_controller/record_identifier.rb
@@ -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
View
2 actionpack/lib/action_controller/routing/builder.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/hash/except'
+
module ActionController
module Routing
class RouteBuilder #:nodoc:
View
8 actionpack/lib/action_controller/routing/route.rb
@@ -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?
View
1 actionpack/lib/action_controller/testing/process.rb
@@ -1,4 +1,5 @@
require 'rack/session/abstract/id'
+require 'active_support/core_ext/object/conversions'
module ActionController #:nodoc:
class TestRequest < ActionDispatch::TestRequest #:nodoc:
View
13 actionpack/lib/action_dispatch.rb
@@ -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'
View
1 actionpack/lib/action_dispatch/http/mime_type.rb
@@ -1,4 +1,5 @@
require 'set'
+require 'active_support/core_ext/class/attribute_accessors'
module Mime
SET = []
View
1 actionpack/lib/action_dispatch/http/request.rb
@@ -3,6 +3,7 @@
require 'strscan'
require 'active_support/memoizable'
+require 'active_support/core_ext/hash/indifferent_access'
module ActionDispatch
class Request < Rack::Request
View
1 actionpack/lib/action_dispatch/http/response.rb
@@ -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
View
13 actionpack/lib/action_view.rb
@@ -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")
View
3 actionpack/lib/action_view/base.rb
@@ -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
View
9 actionpack/lib/action_view/helpers/form_helper.rb
@@ -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
View
1 actionpack/lib/action_view/template/handlers/erb.rb
@@ -1,4 +1,5 @@
require 'erb'
+require 'active_support/core_ext/class/attribute_accessors'
module ActionView
module TemplateHandlers
View
4 actionpack/test/abstract_controller/test_helper.rb
@@ -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
View
3 actionpack/test/abstract_unit2.rb
@@ -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
View
1 actionpack/test/controller/addresses_render_test.rb
@@ -1,4 +1,5 @@
require 'abstract_unit'
+require 'logger'
class Address
def Address.count(conditions = nil, join = nil)
View
1 actionpack/test/controller/base_test.rb
@@ -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.
View
1 actionpack/test/controller/capture_test.rb
@@ -1,4 +1,5 @@
require 'abstract_unit'
+require 'logger'
class CaptureController < ActionController::Base
def self.controller_name; "test"; end
View
1 actionpack/test/controller/helper_test.rb
@@ -1,4 +1,5 @@
require 'abstract_unit'
+require 'active_support/core_ext/kernel/reporting'
ActionController::Base.helpers_dir = File.dirname(__FILE__) + '/../fixtures/helpers'
View
6 activemodel/Rakefile
@@ -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|
View
1 activemodel/test/state_machine/event_test.rb
@@ -1,4 +1,5 @@
require 'test_helper'
+require 'active_model/state_machine/event'
class EventTest < ActiveModel::TestCase
def setup
View
1 activemodel/test/state_machine/state_transition_test.rb
@@ -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
3 activerecord/Rakefile
@@ -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|
View
1 activerecord/lib/active_record.rb
@@ -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.
View
2 activerecord/lib/active_record/associations.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/module/delegation'
+
module ActiveRecord
class InverseOfAssociationNotFoundError < ActiveRecordError #:nodoc:
def initialize(reflection)
View
2 activerecord/lib/active_record/attribute_methods.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/enumerable'
+
module ActiveRecord
module AttributeMethods #:nodoc:
extend ActiveSupport::DependencyModule
View
21 activerecord/lib/active_record/base.rb
@@ -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.
View
1 activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
@@ -1,5 +1,6 @@
require 'monitor'
require 'set'
+require 'active_support/core_ext/module/synchronization'
module ActiveRecord
# Raised when a connection could not be obtained within the connection
View
2 activerecord/lib/active_record/connection_adapters/abstract/quoting.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/big_decimal/conversions'
+
module ActiveRecord
module ConnectionAdapters # :nodoc:
module Quoting
View
2 activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
@@ -12,6 +12,8 @@
require 'active_record/connection_adapters/abstract/connection_specification'
require 'active_record/connection_adapters/abstract/query_cache'
+require 'active_support/core_ext/benchmark'
+
module ActiveRecord
module ConnectionAdapters # :nodoc:
# ActiveRecord supports multiple database systems. AbstractAdapter and
View
1 activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
@@ -1,4 +1,5 @@
require 'active_record/connection_adapters/abstract_adapter'
+require 'active_support/core_ext/kernel/requires'
require 'set'
module MysqlCompat #:nodoc:
View
1 activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -1,4 +1,5 @@
require 'active_record/connection_adapters/abstract_adapter'
+require 'active_support/core_ext/kernel/requires'
begin
require_library_or_gem 'pg'
View
6 activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
@@ -25,9 +25,9 @@ def self.sqlite3_connection(config) # :nodoc:
module ConnectionAdapters #:nodoc:
class SQLite3Adapter < SQLiteAdapter # :nodoc:
def table_structure(table_name)
- returning structure = @connection.table_info(quote_table_name(table_name)) do
- raise(ActiveRecord::StatementInvalid, "Could not find table '#{table_name}'") if structure.empty?
- end
+ structure = @connection.table_info(quote_table_name(table_name))
+ raise(ActiveRecord::StatementInvalid, "Could not find table '#{table_name}'") if structure.empty?
+ structure
end
end
end
View
1 activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
@@ -1,4 +1,5 @@
require 'active_record/connection_adapters/abstract_adapter'
+require 'active_support/core_ext/kernel/requires'
module ActiveRecord
class Base
View
4 activerecord/lib/active_record/dirty.rb
@@ -168,7 +168,9 @@ def field_changed?(attr, old, value)
module ClassMethods
def self.extended(base)
- base.metaclass.alias_method_chain(:alias_attribute, :dirty)
+ class << base
+ alias_method_chain :alias_attribute, :dirty
+ end
end
def alias_attribute_with_dirty(new_name, old_name)
View
1 activerecord/lib/active_record/fixtures.rb
@@ -3,6 +3,7 @@
require 'csv'
require 'active_support/dependencies'
require 'active_support/test_case'
+require 'active_support/core_ext/logger'
if RUBY_VERSION < '1.9'
module YAML #:nodoc:
View
10 activerecord/lib/active_record/migration.rb
@@ -511,11 +511,11 @@ def migrations
raise DuplicateMigrationNameError.new(name.camelize)
end
- klasses << returning(MigrationProxy.new) do |migration|
- migration.name = name.camelize
- migration.version = version
- migration.filename = file
- end
+ migration = MigrationProxy.new
+ migration.name = name.camelize
+ migration.version = version
+ migration.filename = file
+ klasses << migration
end
migrations = migrations.sort_by(&:version)
View
3 activerecord/lib/active_record/named_scope.rb
@@ -1,3 +1,6 @@
+require 'active_support/core_ext/array'
+require 'active_support/core_ext/hash/except'
+
module ActiveRecord
module NamedScope
extend ActiveSupport::DependencyModule
View
3 activerecord/lib/active_record/nested_attributes.rb
@@ -1,3 +1,6 @@
+require 'active_support/core_ext/hash/except'
+require 'active_support/core_ext/object/try'
+
module ActiveRecord
module NestedAttributes #:nodoc:
extend ActiveSupport::DependencyModule
View
4 activerecord/lib/active_record/schema_dumper.rb
@@ -1,5 +1,5 @@
require 'stringio'
-require 'bigdecimal'
+require 'active_support/core_ext/big_decimal'
module ActiveRecord
# This class is used to dump the database schema for some connection to some
@@ -176,4 +176,4 @@ def indexes(table, stream)
end
end
end
-end
+end
View
17 activerecord/lib/active_record/serialization.rb
@@ -1,5 +1,3 @@
-require 'active_support/json'
-
module ActiveRecord #:nodoc:
module Serialization
class Serializer #:nodoc:
@@ -73,16 +71,19 @@ def add_includes(&block)
end
def serializable_record
- returning(serializable_record = {}) do
- serializable_names.each { |name| serializable_record[name] = @record.send(name) }
- add_includes do |association, records, opts|
+ record = {}
+ serializable_names.each { |name| record[name] = @record.send(name) }
+
+ add_includes do |association, records, opts|
+ record[association] =
if records.is_a?(Enumerable)
- serializable_record[association] = records.collect { |r| self.class.new(r, opts).serializable_record }
+ records.collect { |r| self.class.new(r, opts).serializable_record }
else
- serializable_record[association] = self.class.new(records, opts).serializable_record
+ self.class.new(records, opts).serializable_record
end
- end
end
+
+ record
end
def serialize
View
5 activerecord/lib/active_record/serializers/xml_serializer.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/hash/conversions'
+
module ActiveRecord #:nodoc:
module Serialization
# Builds an XML document to represent the model. Some configuration is
@@ -165,8 +167,9 @@ def from_xml(xml)
class XmlSerializer < ActiveRecord::Serialization::Serializer #:nodoc:
def builder
@builder ||= begin
+ require 'builder' unless defined? ::Builder
options[:indent] ||= 2
- builder = options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent])
+ builder = options[:builder] ||= ::Builder::XmlMarkup.new(:indent => options[:indent])
unless options[:skip_instruct]
builder.instruct!
View
5 activerecord/lib/active_record/validations.rb
@@ -1,5 +1,3 @@
-require 'builder'
-
module ActiveRecord
# Raised by <tt>save!</tt> and <tt>create!</tt> when the record is invalid. Use the
# +record+ method to retrieve the record which did not validate.
@@ -247,9 +245,10 @@ def size
# # <error>Address can't be blank</error>
# # </errors>
def to_xml(options={})
+ require 'builder' unless defined? ::Builder
options[:root] ||= "errors"
options[:indent] ||= 2
- options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent])
+ options[:builder] ||= ::Builder::XmlMarkup.new(:indent => options[:indent])
options[:builder].instruct! unless options.delete(:skip_instruct)
options[:builder].errors do |e|
View
1 activerecord/test/cases/aggregations_test.rb
@@ -1,5 +1,6 @@
require "cases/helper"
require 'models/customer'
+require 'active_support/core_ext/exception'
class AggregationsTest < ActiveRecord::TestCase
fixtures :customers
View
1 activerecord/test/cases/associations/eager_load_nested_include_test.rb
@@ -4,6 +4,7 @@
require 'models/comment'
require 'models/category'
require 'models/categorization'
+require 'active_support/core_ext/array/random_access'
module Remembered
extend ActiveSupport::DependencyModule
View
1 activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
@@ -24,6 +24,7 @@
require 'models/member'
require 'models/membership'
require 'models/sponsor'
+require 'active_support/core_ext/string/conversions'
class ProjectWithAfterCreateHook < ActiveRecord::Base
set_table_name 'projects'
View
1 activerecord/test/cases/base_test.rb
@@ -18,6 +18,7 @@
require 'models/warehouse_thing'
require 'models/parrot'
require 'rexml/document'
+require 'active_support/core_ext/exception'
class Category < ActiveRecord::Base; end
class Categorization < ActiveRecord::Base; end
View
5 activerecord/test/cases/finder_test.rb
@@ -485,8 +485,9 @@ def test_bind_empty_enumerable
assert_equal "foo in (#{quoted_nil})", bind('foo in (?)', [])
end
- def test_bind_string
- assert_equal ActiveRecord::Base.connection.quote(''), bind('?', '')
+ def test_bind_empty_string
+ quoted_empty = ActiveRecord::Base.connection.quote('')
+ assert_equal quoted_empty, bind('?', '')
end
def test_bind_chars
View
5 activerecord/test/cases/helper.rb
@@ -15,6 +15,11 @@
require 'cases/repair_helper'
+begin
+ require 'ruby-debug'
+rescue LoadError
+end
+
# Show backtraces for deprecated behavior for quicker cleanup.
ActiveSupport::Deprecation.debug = true
View
3 activerecord/test/cases/named_scope_test.rb
@@ -1,4 +1,5 @@
require "cases/helper"
+require 'active_support/core_ext/array/random_access'
require 'models/post'
require 'models/topic'
require 'models/comment'
@@ -265,7 +266,7 @@ def test_find_all_should_behave_like_select
end
def test_rand_should_select_a_random_object_from_proxy
- assert Topic.approved.rand.is_a?(Topic)
+ assert_kind_of Topic, Topic.approved.rand
end
def test_should_use_where_in_query_for_named_scope
View
1 activerecord/test/cases/nested_attributes_test.rb
@@ -4,6 +4,7 @@
require "models/bird"
require "models/parrot"
require "models/treasure"
+require 'active_support/hash_with_indifferent_access'
module AssertRaiseWithMessage
def assert_raise_with_message(expected_exception, expected_message)
View
2 activerecord/test/models/company_in_module.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/object/misc'
+
module MyApplication
module Business
class Company < ActiveRecord::Base
View
7 activeresource/Rakefile
@@ -34,6 +34,13 @@ Rake::TestTask.new { |t|
t.verbose = true
t.warning = true
}
+task :isolated_test do
+ ruby = File.join(*RbConfig::CONFIG.values_at('bindir', 'RUBY_INSTALL_NAME'))
+ activesupport_path = "#{File.dirname(__FILE__)}/../activesupport/lib"
+ Dir.glob("test/**/*_test.rb").all? do |file|
+ system(ruby, "-Ilib:test:#{activesupport_path}", file)
+ end or raise "Failures"
+end
# Generate the RDoc documentation
View
4 activeresource/lib/active_resource/base.rb
@@ -1,8 +1,10 @@
+require 'active_support'
require 'active_support/core_ext/class/attribute_accessors'
require 'active_support/core_ext/class/inheritable_attributes'
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'
require 'active_support/core_ext/object/misc'
require 'set'
@@ -1027,7 +1029,7 @@ def collection_path(options = nil)
private
# Tries to find a resource for a given collection name; if it fails, then the resource is created
def find_or_create_resource_for_collection(name)
- find_or_create_resource_for(name.to_s.singularize)
+ find_or_create_resource_for(ActiveSupport::Inflector.singularize(name.to_s))
end
# Tries to find a resource in a non empty list of nested modules
View
1 activeresource/test/base/custom_methods_test.rb
@@ -1,6 +1,7 @@
require 'abstract_unit'
require 'fixtures/person'
require 'fixtures/street_address'
+require 'active_support/core_ext/hash/conversions'
class CustomMethodsTest < Test::Unit::TestCase
def setup
View
1 activeresource/test/base/load_test.rb
@@ -2,6 +2,7 @@
require "fixtures/person"
require "fixtures/street_address"
require 'active_support/core_ext/symbol'
+require 'active_support/core_ext/hash/conversions'
module Highrise
class Note < ActiveResource::Base
View
1 activeresource/test/base_test.rb
@@ -3,6 +3,7 @@
require "fixtures/customer"
require "fixtures/street_address"
require "fixtures/beast"
+require 'active_support/core_ext/hash/conversions'
class BaseTest < Test::Unit::TestCase
def setup
View
2 activesupport/Rakefile
@@ -22,8 +22,8 @@ Rake::TestTask.new { |t|
t.warning = true
}
task :isolated_test do
+ ruby = File.join(*RbConfig::CONFIG.values_at('bindir', 'RUBY_INSTALL_NAME'))
Dir['test/**/*_test.rb'].all? do |file|
- ruby = File.join(*RbConfig::CONFIG.values_at('bindir', 'RUBY_INSTALL_NAME'))
system(ruby, '-Ilib:test', file)
end or raise "Failures"
end
View
3 activesupport/lib/active_support/core_ext/object/conversions.rb
@@ -1,3 +1,6 @@
+require 'active_support/core_ext/array/conversions'
+require 'active_support/core_ext/hash/conversions'
+
class Object
# Alias of <tt>to_s</tt>.
def to_param
View
1 railties/Rakefile
@@ -31,6 +31,7 @@ task :test do
system(ruby, '-Itest', "-I#{File.dirname(__FILE__)}/../activesupport/lib", file)
end or raise "Failures"
end
+task :isolated_test => :test
Rake::TestTask.new("regular_test") do |t|
t.libs << 'test' << "#{File.dirname(__FILE__)}/../activesupport/lib"
View
2 railties/lib/initializer.rb
@@ -264,8 +264,8 @@ def set_autoload_paths
# Action Pack, Action Mailer, and Active Resource) are loaded.
def require_frameworks
require 'active_support'
- require 'active_support/core/all'
configuration.frameworks.each { |framework| require(framework.to_s) }
+ require 'active_support/core/all'
rescue LoadError => e
# Re-raise as RuntimeError because Mongrel would swallow LoadError.
raise e.to_s
View
2 railties/lib/rails/plugin.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/kernel/reporting'
+
module Rails
# The Plugin class should be an object which provides the following methods:
#
View
1 railties/test/abstract_unit.rb
@@ -13,7 +13,6 @@
require 'mocha'
require 'active_support'
-require 'active_support/core/all'
require 'active_support/test_case'
if defined?(RAILS_ROOT)
View
1 railties/test/plugin_test_helper.rb
@@ -3,7 +3,6 @@
require 'test/unit'
require 'active_support'
-require 'active_support/core/all'
require 'initializer'
require File.join(File.dirname(__FILE__), 'abstract_unit')

0 comments on commit e8550ee

Please sign in to comment.
Something went wrong with that request. Please try again.