mirror of https://github.com/rails/rails
Cherry-pick core extensions
This commit is contained in:
parent
fa5da8ad54
commit
e8550ee032
2
Rakefile
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|
|
||||
|
|
|
@ -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 @@ end
|
|||
|
||||
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 @@ module ActionController
|
|||
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 @@ module ActionController
|
|||
# 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 @@ module ActionController
|
|||
# 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 @@ module ActionController
|
|||
# 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 @@ module ActionController
|
|||
# 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 'stringio'
|
|||
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 'cgi'
|
|||
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 @@ module ActionView
|
|||
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 @@ $:.unshift(File.dirname(__FILE__) + '/../lib')
|
|||
|
||||
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 @@ begin
|
|||
Debugger.start
|
||||
rescue LoadError
|
||||
# Debugging disabled. `gem install ruby-debug` to enable.
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,7 +5,6 @@ $:.unshift(File.dirname(__FILE__) + '/lib')
|
|||
|
||||
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 @@ module ActionController
|
|||
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'
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 @@ module ActiveRecord #:nodoc:
|
|||
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 @@ module ActiveRecord #:nodoc:
|
|||
# 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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
require 'active_support/core_ext/big_decimal/conversions'
|
||||
|
||||
module ActiveRecord
|
||||
module ConnectionAdapters # :nodoc:
|
||||
module Quoting
|
||||
|
|
|
@ -12,6 +12,8 @@ require 'active_record/connection_adapters/abstract/connection_pool'
|
|||
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
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
require 'active_record/connection_adapters/abstract_adapter'
|
||||
require 'active_support/core_ext/kernel/requires'
|
||||
require 'set'
|
||||
|
||||
module MysqlCompat #:nodoc:
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
require 'active_record/connection_adapters/abstract_adapter'
|
||||
require 'active_support/core_ext/kernel/requires'
|
||||
|
||||
begin
|
||||
require_library_or_gem 'pg'
|
||||
|
|
|
@ -25,9 +25,9 @@ module ActiveRecord
|
|||
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
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
require 'active_record/connection_adapters/abstract_adapter'
|
||||
require 'active_support/core_ext/kernel/requires'
|
||||
|
||||
module ActiveRecord
|
||||
class Base
|
||||
|
|
|
@ -168,7 +168,9 @@ module ActiveRecord
|
|||
|
||||
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)
|
||||
|
|
|
@ -3,6 +3,7 @@ require 'yaml'
|
|||
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:
|
||||
|
|
|
@ -511,11 +511,11 @@ module ActiveRecord
|
|||
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)
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
require 'active_support/core_ext/array'
|
||||
require 'active_support/core_ext/hash/except'
|
||||
|
||||
module ActiveRecord
|
||||
module NamedScope
|
||||
extend ActiveSupport::DependencyModule
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 @@ HEADER
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
require 'active_support/json'
|
||||
|
||||
module ActiveRecord #:nodoc:
|
||||
module Serialization
|
||||
class Serializer #:nodoc:
|
||||
|
@ -73,16 +71,19 @@ module ActiveRecord #:nodoc:
|
|||
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
|
||||
|
|
|
@ -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 @@ module ActiveRecord #:nodoc:
|
|||
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!
|
||||
|
|
|
@ -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 @@ module ActiveRecord
|
|||
# # <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|
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
require "cases/helper"
|
||||
require 'models/customer'
|
||||
require 'active_support/core_ext/exception'
|
||||
|
||||
class AggregationsTest < ActiveRecord::TestCase
|
||||
fixtures :customers
|
||||
|
|
|
@ -4,6 +4,7 @@ require 'models/author'
|
|||
require 'models/comment'
|
||||
require 'models/category'
|
||||
require 'models/categorization'
|
||||
require 'active_support/core_ext/array/random_access'
|
||||
|
||||
module Remembered
|
||||
extend ActiveSupport::DependencyModule
|
||||
|
|
|
@ -24,6 +24,7 @@ require 'models/club'
|
|||
require 'models/member'
|
||||
require 'models/membership'
|
||||
require 'models/sponsor'
|
||||
require 'active_support/core_ext/string/conversions'
|
||||
|
||||
class ProjectWithAfterCreateHook < ActiveRecord::Base
|
||||
set_table_name 'projects'
|
||||
|
|
|
@ -18,6 +18,7 @@ require 'models/minimalistic'
|
|||
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
|
||||
|
|
|
@ -485,8 +485,9 @@ class FinderTest < ActiveRecord::TestCase
|
|||
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
|
||||
|
|
|
@ -15,6 +15,11 @@ require 'connection'
|
|||
|
||||
require 'cases/repair_helper'
|
||||
|
||||
begin
|
||||
require 'ruby-debug'
|
||||
rescue LoadError
|
||||
end
|
||||
|
||||
# Show backtraces for deprecated behavior for quicker cleanup.
|
||||
ActiveSupport::Deprecation.debug = true
|
||||
|
||||
|
|
|
@ -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 @@ class NamedScopeTest < ActiveRecord::TestCase
|
|||
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
|
||||
|
|
|
@ -4,6 +4,7 @@ require "models/ship"
|
|||
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)
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
require 'active_support/core_ext/object/misc'
|
||||
|
||||
module MyApplication
|
||||
module Business
|
||||
class Company < ActiveRecord::Base
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 @@ module ActiveResource
|
|||
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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -2,6 +2,7 @@ require 'abstract_unit'
|
|||
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
|
||||
|
|
|
@ -3,6 +3,7 @@ require "fixtures/person"
|
|||
require "fixtures/customer"
|
||||
require "fixtures/street_address"
|
||||
require "fixtures/beast"
|
||||
require 'active_support/core_ext/hash/conversions'
|
||||
|
||||
class BaseTest < Test::Unit::TestCase
|
||||
def setup
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -264,8 +264,8 @@ module Rails
|
|||
# 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
|
||||
|
|
|
@ -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:
|
||||
#
|
||||
|
|
|
@ -13,7 +13,6 @@ gem 'mocha', '>= 0.9.5'
|
|||
require 'mocha'
|
||||
|
||||
require 'active_support'
|
||||
require 'active_support/core/all'
|
||||
require 'active_support/test_case'
|
||||
|
||||
if defined?(RAILS_ROOT)
|
||||
|
|
|
@ -3,7 +3,6 @@ $:.unshift File.dirname(__FILE__) + "/../../activesupport/lib"
|
|||
|
||||
require 'test/unit'
|
||||
require 'active_support'
|
||||
require 'active_support/core/all'
|
||||
require 'initializer'
|
||||
require File.join(File.dirname(__FILE__), 'abstract_unit')
|
||||
|
||||
|
|
Loading…
Reference in New Issue