From a7ccc7c79fa69cea3b7d19bcaa4df3c2932238d8 Mon Sep 17 00:00:00 2001
From: Jeremy Kemper <jeremy@bitsweat.net>
Date: Tue, 12 May 2009 17:58:37 -0700
Subject: Remove support for deprecated validation message interpolation format

---
 activerecord/lib/active_record.rb                  |  1 -
 .../i18n_interpolation_deprecation.rb              | 26 -----------------
 activerecord/test/cases/validations_i18n_test.rb   | 34 +++++-----------------
 3 files changed, 8 insertions(+), 53 deletions(-)
 delete mode 100644 activerecord/lib/active_record/i18n_interpolation_deprecation.rb

(limited to 'activerecord')

diff --git a/activerecord/lib/active_record.rb b/activerecord/lib/active_record.rb
index 06d6c87090..c9e9a84ce7 100644
--- a/activerecord/lib/active_record.rb
+++ b/activerecord/lib/active_record.rb
@@ -75,5 +75,4 @@ module ActiveRecord
   end
 end
 
-require 'active_record/i18n_interpolation_deprecation'
 I18n.load_path << File.dirname(__FILE__) + '/active_record/locale/en.yml'
diff --git a/activerecord/lib/active_record/i18n_interpolation_deprecation.rb b/activerecord/lib/active_record/i18n_interpolation_deprecation.rb
deleted file mode 100644
index cd634e1b8d..0000000000
--- a/activerecord/lib/active_record/i18n_interpolation_deprecation.rb
+++ /dev/null
@@ -1,26 +0,0 @@
-# Deprecates the use of the former message interpolation syntax in activerecord
-# as in "must have %d characters". The new syntax uses explicit variable names
-# as in "{{value}} must have {{count}} characters".
-
-require 'i18n/backend/simple'
-module I18n
-  module Backend
-    class Simple
-      DEPRECATED_INTERPOLATORS = { '%d' => '{{count}}', '%s' => '{{value}}' }
-
-      protected
-        def interpolate_with_deprecated_syntax(locale, string, values = {})
-          return string unless string.is_a?(String)
-
-          string = string.gsub(/%d|%s/) do |s|
-            instead = DEPRECATED_INTERPOLATORS[s]
-            ActiveSupport::Deprecation.warn "using #{s} in messages is deprecated; use #{instead} instead."
-            instead
-          end
-
-          interpolate_without_deprecated_syntax(locale, string, values)
-        end
-        alias_method_chain :interpolate, :deprecated_syntax
-    end
-  end
-end
\ No newline at end of file
diff --git a/activerecord/test/cases/validations_i18n_test.rb b/activerecord/test/cases/validations_i18n_test.rb
index 66982346e9..20d1369a64 100644
--- a/activerecord/test/cases/validations_i18n_test.rb
+++ b/activerecord/test/cases/validations_i18n_test.rb
@@ -38,35 +38,17 @@ class ActiveRecordValidationsI18nTests < ActiveSupport::TestCase
     end
   end
 
-  def test_default_error_messages_is_deprecated
-    assert_deprecated('ActiveRecord::Errors.default_error_messages') do
-      ActiveRecord::Errors.default_error_messages
+  def test_percent_s_interpolation_syntax_in_error_messages_was_deprecated
+    assert_not_deprecated do
+      default = "%s interpolation syntax was deprecated"
+      assert_equal default, I18n.t(:does_not_exist, :default => default, :value => 'this')
     end
   end
 
-  def test_percent_s_interpolation_syntax_in_error_messages_still_works
-    ActiveSupport::Deprecation.silence do
-      result = I18n.t :does_not_exist, :default => "%s interpolation syntax is deprecated", :value => 'this'
-      assert_equal result, "this interpolation syntax is deprecated"
-    end
-  end
-
-  def test_percent_s_interpolation_syntax_in_error_messages_is_deprecated
-    assert_deprecated('using %s in messages') do
-      I18n.t :does_not_exist, :default => "%s interpolation syntax is deprected", :value => 'this'
-    end
-  end
-
-  def test_percent_d_interpolation_syntax_in_error_messages_still_works
-    ActiveSupport::Deprecation.silence do
-      result = I18n.t :does_not_exist, :default => "%d interpolation syntaxes are deprecated", :count => 2
-      assert_equal result, "2 interpolation syntaxes are deprecated"
-    end
-  end
-
-  def test_percent_d_interpolation_syntax_in_error_messages_is_deprecated
-    assert_deprecated('using %d in messages') do
-      I18n.t :does_not_exist, :default => "%d interpolation syntaxes are deprected", :count => 2
+  def test_percent_d_interpolation_syntax_in_error_messages_was_deprecated
+    assert_not_deprecated do
+      default = "%d interpolation syntaxes are deprecated"
+      assert_equal default, I18n.t(:does_not_exist, :default => default, :count => 2)
     end
   end
 
-- 
cgit v1.2.3


From fa5da8ad54d68ea0484825845eb6f6a8e8bca361 Mon Sep 17 00:00:00 2001
From: Jeremy Kemper <jeremy@bitsweat.net>
Date: Wed, 13 May 2009 01:06:53 -0700
Subject: isolated_test task

---
 activerecord/Rakefile | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

(limited to 'activerecord')

diff --git a/activerecord/Rakefile b/activerecord/Rakefile
index 5905c67e29..892d52f30d 100644
--- a/activerecord/Rakefile
+++ b/activerecord/Rakefile
@@ -33,20 +33,28 @@ task :test => defined?(JRUBY_VERSION) ?
   %w(test_jdbcmysql test_jdbcsqlite3 test_jdbcpostgresql) :
   %w(test_mysql test_sqlite3 test_postgresql)
 
-for adapter in %w( mysql postgresql sqlite sqlite3 firebird db2 oracle sybase openbase frontbase jdbcmysql jdbcpostgresql jdbcsqlite3 jdbcderby jdbch2 jdbchsqldb )
+%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|
-    if adapter =~ /jdbc/
-      t.libs << "test" << "test/connections/jdbc_#{adapter}"
-    else
-      t.libs << "test" << "test/connections/native_#{adapter}"
-    end
+    connection_path = "test/connections/#{adapter =~ /jdbc/ ? 'jdbc' : 'native'}_#{adapter}"
     adapter_short = adapter == 'db2' ? adapter : adapter[/^[a-z]+/]
+    t.libs << "test" << connection_path
     t.test_files=Dir.glob( "test/cases/**/*_test{,_#{adapter_short}}.rb" ).sort
     t.verbose = true
   }
 
+  task "isolated_test_#{adapter}" do
+    connection_path = "test/connections/#{adapter =~ /jdbc/ ? 'jdbc' : 'native'}_#{adapter}"
+    adapter_short = adapter == 'db2' ? adapter : adapter[/^[a-z]+/]
+    puts [adapter, adapter_short, connection_path].inspect
+    ruby = File.join(*RbConfig::CONFIG.values_at('bindir', 'RUBY_INSTALL_NAME'))
+    Dir["test/cases/**/*_test{,_#{adapter_short}}.rb"].all? do |file|
+      system(ruby, "-Ilib:test:#{connection_path}", file)
+    end or raise "Failures"
+  end
+
   namespace adapter do
     task :test => "test_#{adapter}"
+    task :isolated_test => "isolated_test_#{adapter}"
   end
 end
 
-- 
cgit v1.2.3


From e8550ee0329586b32de425e905c7af7e65bc78a8 Mon Sep 17 00:00:00 2001
From: Jeremy Kemper <jeremy@bitsweat.net>
Date: Wed, 13 May 2009 01:10:37 -0700
Subject: Cherry-pick core extensions

---
 activerecord/Rakefile                               |  3 +++
 activerecord/lib/active_record.rb                   |  1 -
 activerecord/lib/active_record/associations.rb      |  2 ++
 activerecord/lib/active_record/attribute_methods.rb |  2 ++
 activerecord/lib/active_record/base.rb              | 21 +++++++++++++++------
 .../connection_adapters/abstract/connection_pool.rb |  1 +
 .../connection_adapters/abstract/quoting.rb         |  2 ++
 .../connection_adapters/abstract_adapter.rb         |  2 ++
 .../connection_adapters/mysql_adapter.rb            |  1 +
 .../connection_adapters/postgresql_adapter.rb       |  1 +
 .../connection_adapters/sqlite3_adapter.rb          |  6 +++---
 .../connection_adapters/sqlite_adapter.rb           |  1 +
 activerecord/lib/active_record/dirty.rb             |  4 +++-
 activerecord/lib/active_record/fixtures.rb          |  1 +
 activerecord/lib/active_record/migration.rb         | 10 +++++-----
 activerecord/lib/active_record/named_scope.rb       |  3 +++
 activerecord/lib/active_record/nested_attributes.rb |  3 +++
 activerecord/lib/active_record/schema_dumper.rb     |  4 ++--
 activerecord/lib/active_record/serialization.rb     | 17 +++++++++--------
 .../lib/active_record/serializers/xml_serializer.rb |  5 ++++-
 activerecord/lib/active_record/validations.rb       |  5 ++---
 activerecord/test/cases/aggregations_test.rb        |  1 +
 .../associations/eager_load_nested_include_test.rb  |  1 +
 .../has_and_belongs_to_many_associations_test.rb    |  1 +
 activerecord/test/cases/base_test.rb                |  1 +
 activerecord/test/cases/finder_test.rb              |  5 +++--
 activerecord/test/cases/helper.rb                   |  5 +++++
 activerecord/test/cases/named_scope_test.rb         |  3 ++-
 activerecord/test/cases/nested_attributes_test.rb   |  1 +
 activerecord/test/models/company_in_module.rb       |  2 ++
 30 files changed, 82 insertions(+), 33 deletions(-)

(limited to 'activerecord')

diff --git a/activerecord/Rakefile b/activerecord/Rakefile
index 892d52f30d..0b3f50d17e 100644
--- a/activerecord/Rakefile
+++ b/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|
diff --git a/activerecord/lib/active_record.rb b/activerecord/lib/active_record.rb
index c9e9a84ce7..2d98239052 100644
--- a/activerecord/lib/active_record.rb
+++ b/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.
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index e2dd36158f..c5e4df4950 100755
--- a/activerecord/lib/active_record/associations.rb
+++ b/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)
diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb
index 8d68d77eac..55d9a4d15d 100644
--- a/activerecord/lib/active_record/attribute_methods.rb
+++ b/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
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 97c36a675d..b9ba727a3f 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/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 @@ 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.
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
index e8e736bf38..500dafdc2e 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
+++ b/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
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb b/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb
index 3a7bf35248..720fba29e9 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb
+++ b/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
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
index a8cd9f033b..91b111ab55 100755
--- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
@@ -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
diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
index 9300df28ee..d5536e4d67 100644
--- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
+++ b/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:
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
index 4961793866..002696d2c4 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
+++ b/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'
diff --git a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
index 75420f69aa..5eef692d05 100644
--- a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
@@ -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
diff --git a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
index 05334a830a..c9d0c9574f 100644
--- a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
+++ b/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
diff --git a/activerecord/lib/active_record/dirty.rb b/activerecord/lib/active_record/dirty.rb
index fac6ca40d3..ac84f6b209 100644
--- a/activerecord/lib/active_record/dirty.rb
+++ b/activerecord/lib/active_record/dirty.rb
@@ -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)
diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb
index 91b4b4e182..e30fcf9a4f 100644
--- a/activerecord/lib/active_record/fixtures.rb
+++ b/activerecord/lib/active_record/fixtures.rb
@@ -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:
diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb
index 657acd6dc0..a7be3539d5 100644
--- a/activerecord/lib/active_record/migration.rb
+++ b/activerecord/lib/active_record/migration.rb
@@ -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)
diff --git a/activerecord/lib/active_record/named_scope.rb b/activerecord/lib/active_record/named_scope.rb
index 32bb36c07c..07f98dc743 100644
--- a/activerecord/lib/active_record/named_scope.rb
+++ b/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
diff --git a/activerecord/lib/active_record/nested_attributes.rb b/activerecord/lib/active_record/nested_attributes.rb
index 1ea2f53fd8..c532d3dfa3 100644
--- a/activerecord/lib/active_record/nested_attributes.rb
+++ b/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
diff --git a/activerecord/lib/active_record/schema_dumper.rb b/activerecord/lib/active_record/schema_dumper.rb
index 557a554966..de530a3456 100644
--- a/activerecord/lib/active_record/schema_dumper.rb
+++ b/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 @@ HEADER
         end
       end
   end
-end
\ No newline at end of file
+end
diff --git a/activerecord/lib/active_record/serialization.rb b/activerecord/lib/active_record/serialization.rb
index 78f66c3a73..7959f2b510 100644
--- a/activerecord/lib/active_record/serialization.rb
+++ b/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 @@ 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
diff --git a/activerecord/lib/active_record/serializers/xml_serializer.rb b/activerecord/lib/active_record/serializers/xml_serializer.rb
index fa75874603..4eaf9531e2 100644
--- a/activerecord/lib/active_record/serializers/xml_serializer.rb
+++ b/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 @@ 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!
diff --git a/activerecord/lib/active_record/validations.rb b/activerecord/lib/active_record/validations.rb
index 9907a3c9b7..b6e848fa79 100644
--- a/activerecord/lib/active_record/validations.rb
+++ b/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 @@ 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|
diff --git a/activerecord/test/cases/aggregations_test.rb b/activerecord/test/cases/aggregations_test.rb
index 4e0e1c7f15..8b6ec04018 100644
--- a/activerecord/test/cases/aggregations_test.rb
+++ b/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
diff --git a/activerecord/test/cases/associations/eager_load_nested_include_test.rb b/activerecord/test/cases/associations/eager_load_nested_include_test.rb
index 5f824f9c74..cb7fe9698b 100644
--- a/activerecord/test/cases/associations/eager_load_nested_include_test.rb
+++ b/activerecord/test/cases/associations/eager_load_nested_include_test.rb
@@ -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
diff --git a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
index 5e8b2cadfc..8dc95806b9 100644
--- a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
@@ -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'
diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb
index 7ca2807f7e..59aa6953e3 100755
--- a/activerecord/test/cases/base_test.rb
+++ b/activerecord/test/cases/base_test.rb
@@ -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
diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb
index 28eb311618..ad4588db69 100644
--- a/activerecord/test/cases/finder_test.rb
+++ b/activerecord/test/cases/finder_test.rb
@@ -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
diff --git a/activerecord/test/cases/helper.rb b/activerecord/test/cases/helper.rb
index 1ec52ac24d..05e92433cd 100644
--- a/activerecord/test/cases/helper.rb
+++ b/activerecord/test/cases/helper.rb
@@ -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
 
diff --git a/activerecord/test/cases/named_scope_test.rb b/activerecord/test/cases/named_scope_test.rb
index ae6a54a5bd..7dcea6d42e 100644
--- a/activerecord/test/cases/named_scope_test.rb
+++ b/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 @@ 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
diff --git a/activerecord/test/cases/nested_attributes_test.rb b/activerecord/test/cases/nested_attributes_test.rb
index f1741ed54d..f31275163d 100644
--- a/activerecord/test/cases/nested_attributes_test.rb
+++ b/activerecord/test/cases/nested_attributes_test.rb
@@ -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)
diff --git a/activerecord/test/models/company_in_module.rb b/activerecord/test/models/company_in_module.rb
index 7f02403d5a..3c34efbe16 100644
--- a/activerecord/test/models/company_in_module.rb
+++ b/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
-- 
cgit v1.2.3


From 4f291fa528e5faad03def69ae7ac98224ab859db Mon Sep 17 00:00:00 2001
From: Jeremy Kemper <jeremy@bitsweat.net>
Date: Wed, 13 May 2009 11:55:19 -0700
Subject: Simple examples for require profiling

---
 activerecord/examples/simple.rb | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
 create mode 100644 activerecord/examples/simple.rb

(limited to 'activerecord')

diff --git a/activerecord/examples/simple.rb b/activerecord/examples/simple.rb
new file mode 100644
index 0000000000..c12f746992
--- /dev/null
+++ b/activerecord/examples/simple.rb
@@ -0,0 +1,14 @@
+$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
+require 'active_record'
+
+class Person < ActiveRecord::Base
+  establish_connection :adapter => 'sqlite3', :database => 'foobar.db'
+  connection.create_table table_name, :force => true do |t|
+    t.string :name
+  end
+end
+
+bob = Person.create!(:name => 'bob')
+puts Person.all.inspect
+bob.destroy
+puts Person.all.inspect
-- 
cgit v1.2.3


From afcbdfc15f919a470e4cfca97fb0084eebd2ab1f Mon Sep 17 00:00:00 2001
From: Peter Marklund <peter_marklund@fastmail.fm>
Date: Thu, 14 May 2009 09:30:16 +0200
Subject: Changed ActiveRecord::Base#exists? to invoke find_initial so that it
 is compatible with, and doesn't lose, :include scopes (references to eager
 loaded tables)

Signed-off-by: Michael Koziarski <michael@koziarski.com>
[#2543 state:committed]
---
 activerecord/lib/active_record/base.rb | 11 +++--------
 activerecord/test/cases/finder_test.rb |  6 ++++++
 2 files changed, 9 insertions(+), 8 deletions(-)

(limited to 'activerecord')

diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index b9ba727a3f..54ec0e841f 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -697,14 +697,9 @@ module ActiveRecord #:nodoc:
       #   Person.exists?(['name LIKE ?', "%#{query}%"])
       #   Person.exists?
       def exists?(id_or_conditions = {})
-        connection.select_all(
-          construct_finder_sql(
-            :select     => "#{quoted_table_name}.#{primary_key}",
-            :conditions => expand_id_conditions(id_or_conditions),
-            :limit      => 1
-          ),
-          "#{name} Exists"
-        ).size > 0
+        find_initial(
+          :select => "#{quoted_table_name}.#{primary_key}",
+          :conditions => expand_id_conditions(id_or_conditions)) ? true : false
       end
 
       # Creates an object (or multiple objects) and saves it to the database, if validations pass.
diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb
index ad4588db69..d0d7094e30 100644
--- a/activerecord/test/cases/finder_test.rb
+++ b/activerecord/test/cases/finder_test.rb
@@ -119,6 +119,12 @@ class FinderTest < ActiveRecord::TestCase
       Address.new(existing_address.street + "1", existing_address.city, existing_address.country))
   end
 
+  def test_exists_with_scoped_include
+    Developer.with_scope(:find => { :include => :projects, :order => "projects.name" }) do
+      assert Developer.exists?
+    end
+  end
+
   def test_find_by_array_of_one_id
     assert_kind_of(Array, Topic.find([ 1 ]))
     assert_equal(1, Topic.find([ 1 ]).length)
-- 
cgit v1.2.3


From 8e6a18d8672f7efe6ef79b49185e4a6a23e4e547 Mon Sep 17 00:00:00 2001
From: Yehuda Katz <wycats@gmail.com>
Date: Sat, 16 May 2009 12:09:25 -0700
Subject: Get AR CI passing again by requiring the entire core_ext

  Note that this includes Time and Date; we should
  really figure out what parts of core_ext are really
  required for AR and require just those.
---
 activerecord/lib/active_record.rb | 3 +++
 1 file changed, 3 insertions(+)

(limited to 'activerecord')

diff --git a/activerecord/lib/active_record.rb b/activerecord/lib/active_record.rb
index 2d98239052..b5c17cb23b 100644
--- a/activerecord/lib/active_record.rb
+++ b/activerecord/lib/active_record.rb
@@ -25,6 +25,9 @@ activesupport_path = "#{File.dirname(__FILE__)}/../../activesupport/lib"
 $:.unshift(activesupport_path) if File.directory?(activesupport_path)
 require 'active_support'
 
+# TODO: Figure out what parts of AS are *actually* required and use those
+require 'active_support/core_ext'
+
 module ActiveRecord
   # TODO: Review explicit loads to see if they will automatically be handled by the initilizer.
   def self.load_all!
-- 
cgit v1.2.3


From 25724eede9b5a62c74b3b78245944638f1cfcef4 Mon Sep 17 00:00:00 2001
From: Daniel Guettler <daniel.guettler@gmail.com>
Date: Sun, 17 May 2009 14:48:20 +0200
Subject: has_one :through should not create a new association when assigned
 nil [#698 state:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
---
 .../associations/has_one_through_association.rb          | 16 ++++++++--------
 .../associations/has_one_through_associations_test.rb    |  9 ++++++++-
 2 files changed, 16 insertions(+), 9 deletions(-)

(limited to 'activerecord')

diff --git a/activerecord/lib/active_record/associations/has_one_through_association.rb b/activerecord/lib/active_record/associations/has_one_through_association.rb
index 8073ebaf9f..d93c8e7852 100644
--- a/activerecord/lib/active_record/associations/has_one_through_association.rb
+++ b/activerecord/lib/active_record/associations/has_one_through_association.rb
@@ -1,31 +1,31 @@
 module ActiveRecord
   module Associations
     class HasOneThroughAssociation < HasManyThroughAssociation
-      
+
       def create_through_record(new_value) #nodoc:
         klass = @reflection.through_reflection.klass
 
         current_object = @owner.send(@reflection.through_reflection.name)
-        
+
         if current_object
-          current_object.update_attributes(construct_join_attributes(new_value))
+          new_value ? current_object.update_attributes(construct_join_attributes(new_value)) : current_object.destroy
         else
-          @owner.send(@reflection.through_reflection.name,  klass.send(:create, construct_join_attributes(new_value)))
+          @owner.send(@reflection.through_reflection.name,  klass.send(:create, construct_join_attributes(new_value))) if new_value
         end
       end
-      
+
     private
       def find(*args)
         super(args.merge(:limit => 1))
       end
-    
+
       def find_target
         super.first
       end
 
       def reset_target!
         @target = nil
-      end        
-    end        
+      end
+    end
   end
 end
diff --git a/activerecord/test/cases/associations/has_one_through_associations_test.rb b/activerecord/test/cases/associations/has_one_through_associations_test.rb
index 12c598751b..ab6e6d20fc 100644
--- a/activerecord/test/cases/associations/has_one_through_associations_test.rb
+++ b/activerecord/test/cases/associations/has_one_through_associations_test.rb
@@ -43,7 +43,14 @@ class HasOneThroughAssociationsTest < ActiveRecord::TestCase
       @member.reload      
     end
   end
-  
+
+  def test_set_record_to_nil_should_delete_association
+    @member.club = nil
+    @member.reload
+    assert_equal nil, @member.current_membership
+    assert_nil @member.club
+  end
+
   def test_has_one_through_polymorphic
     assert_equal clubs(:moustache_club), @member.sponsor_club
   end
-- 
cgit v1.2.3


From 4e8c36a7417e5d447c9b15d5c61df0c014ee6d3b Mon Sep 17 00:00:00 2001
From: Chris Kampmeier <chris@kampers.net>
Date: Mon, 16 Mar 2009 05:56:32 -0700
Subject: Implement #many? for NamedScope and AssociationCollection using #size
 [#1500 state:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
---
 activerecord/CHANGELOG                             |  2 ++
 .../associations/association_collection.rb         |  9 +++++
 activerecord/lib/active_record/named_scope.rb      | 11 +++++-
 .../associations/has_many_associations_test.rb     | 39 ++++++++++++++++++++++
 activerecord/test/cases/named_scope_test.rb        | 34 +++++++++++++++++++
 5 files changed, 94 insertions(+), 1 deletion(-)

(limited to 'activerecord')

diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index d58b44144b..411b640c9e 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,5 +1,7 @@
 *Edge*
 
+* Implement #many? for NamedScope and AssociationCollection using #size. #1500 [Chris Kampmeier]
+
 * Added :touch option to belongs_to associations that will touch the parent record when the current record is saved or destroyed [DHH]
 
 * Added ActiveRecord::Base#touch to update the updated_at/on attributes (or another specified timestamp) with the current time [DHH]
diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb
index 26987dde97..e12f6be35d 100644
--- a/activerecord/lib/active_record/associations/association_collection.rb
+++ b/activerecord/lib/active_record/associations/association_collection.rb
@@ -302,6 +302,15 @@ module ActiveRecord
         end
       end
 
+      # Returns true if the collection has more than 1 record. Equivalent to collection.size > 1.
+      def many?
+        if block_given?
+          method_missing(:many?) { |*block_args| yield(*block_args) }
+        else
+          size > 1
+        end
+      end
+
       def uniq(collection = self)
         seen = Set.new
         collection.inject([]) do |kept, record|
diff --git a/activerecord/lib/active_record/named_scope.rb b/activerecord/lib/active_record/named_scope.rb
index 07f98dc743..e7151a3d47 100644
--- a/activerecord/lib/active_record/named_scope.rb
+++ b/activerecord/lib/active_record/named_scope.rb
@@ -109,7 +109,7 @@ module ActiveRecord
 
     class Scope
       attr_reader :proxy_scope, :proxy_options, :current_scoped_methods_when_defined
-      NON_DELEGATE_METHODS = %w(nil? send object_id class extend find size count sum average maximum minimum paginate first last empty? any? respond_to?).to_set
+      NON_DELEGATE_METHODS = %w(nil? send object_id class extend find size count sum average maximum minimum paginate first last empty? any? many? respond_to?).to_set
       [].methods.each do |m|
         unless m =~ /^__/ || NON_DELEGATE_METHODS.include?(m.to_s)
           delegate m, :to => :proxy_found
@@ -168,6 +168,15 @@ module ActiveRecord
         end
       end
 
+      # Returns true if the named scope has more than 1 matching record.
+      def many?
+        if block_given?
+          proxy_found.many? { |*block_args| yield(*block_args) }
+        else
+          size > 1
+        end
+      end
+
       protected
       def proxy_found
         @found || load_found
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb
index 5df74fcdcd..d99424f9cd 100644
--- a/activerecord/test/cases/associations/has_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_associations_test.rb
@@ -1023,6 +1023,45 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
     assert firm.clients.loaded?
   end
 
+  def test_calling_many_should_count_instead_of_loading_association
+    firm = companies(:first_firm)
+    assert_queries(1) do
+      firm.clients.many?  # use count query
+    end
+    assert !firm.clients.loaded?
+  end
+
+  def test_calling_many_on_loaded_association_should_not_use_query
+    firm = companies(:first_firm)
+    firm.clients.collect  # force load
+    assert_no_queries { assert firm.clients.many? }
+  end
+
+  def test_calling_many_should_defer_to_collection_if_using_a_block
+    firm = companies(:first_firm)
+    assert_queries(1) do
+      firm.clients.expects(:size).never
+      firm.clients.many? { true }
+    end
+    assert firm.clients.loaded?
+  end
+
+  def test_calling_many_should_return_false_if_none_or_one
+    firm = companies(:another_firm)
+    assert !firm.clients_like_ms.many?
+    assert_equal 0, firm.clients_like_ms.size
+
+    firm = companies(:first_firm)
+    assert !firm.limited_clients.many?
+    assert_equal 1, firm.limited_clients.size
+  end
+
+  def test_calling_many_should_return_true_if_more_than_one
+    firm = companies(:first_firm)
+    assert firm.clients.many?
+    assert_equal 2, firm.clients.size
+  end
+
   def test_joins_with_namespaced_model_should_use_correct_type
     old = ActiveRecord::Base.store_full_sti_class
     ActiveRecord::Base.store_full_sti_class = true
diff --git a/activerecord/test/cases/named_scope_test.rb b/activerecord/test/cases/named_scope_test.rb
index 7dcea6d42e..69d01d5c2a 100644
--- a/activerecord/test/cases/named_scope_test.rb
+++ b/activerecord/test/cases/named_scope_test.rb
@@ -235,6 +235,40 @@ class NamedScopeTest < ActiveRecord::TestCase
     assert_no_queries { assert topics.any? }
   end
 
+  def test_many_should_not_load_results
+    topics = Topic.base
+    assert_queries(2) do
+      topics.many?   # use count query
+      topics.collect # force load
+      topics.many?   # use loaded (no query)
+    end
+  end
+
+  def test_many_should_call_proxy_found_if_using_a_block
+    topics = Topic.base
+    assert_queries(1) do
+      topics.expects(:size).never
+      topics.many? { true }
+    end
+  end
+
+  def test_many_should_not_fire_query_if_named_scope_loaded
+    topics = Topic.base
+    topics.collect # force load
+    assert_no_queries { assert topics.many? }
+  end
+
+  def test_many_should_return_false_if_none_or_one
+    topics = Topic.base.scoped(:conditions => {:id => 0})
+    assert !topics.many?
+    topics = Topic.base.scoped(:conditions => {:id => 1})
+    assert !topics.many?
+  end
+
+  def test_many_should_return_true_if_more_than_one
+    assert Topic.base.many?
+  end
+
   def test_should_build_with_proxy_options
     topic = Topic.approved.build({})
     assert topic.approved
-- 
cgit v1.2.3


From b33c0d98329b97f8f540ba455d419d5046e6bb39 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mislav=20Marohni=C4=87?= <mislav.marohnic@gmail.com>
Date: Sun, 17 May 2009 13:51:35 -0500
Subject: replace the aaa_create_tables_test hack with loading test database
 schema in the test helper [#2663 state:resolved]

Signed-off-by: Joshua Peek <josh@joshpeek.com>
---
 activerecord/test/cases/aaa_create_tables_test.rb | 24 -----------------------
 activerecord/test/cases/helper.rb                 | 18 +++++++++++++++++
 activerecord/test/schema/schema.rb                |  5 ++++-
 activerecord/test/schema/schema2.rb               |  6 ------
 4 files changed, 22 insertions(+), 31 deletions(-)
 delete mode 100644 activerecord/test/cases/aaa_create_tables_test.rb
 delete mode 100644 activerecord/test/schema/schema2.rb

(limited to 'activerecord')

diff --git a/activerecord/test/cases/aaa_create_tables_test.rb b/activerecord/test/cases/aaa_create_tables_test.rb
deleted file mode 100644
index 3911afac49..0000000000
--- a/activerecord/test/cases/aaa_create_tables_test.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-# The filename begins with "aaa" to ensure this is the first test.
-require "cases/helper"
-
-class AAACreateTablesTest < ActiveRecord::TestCase
-  self.use_transactional_fixtures = false
-
-  def test_load_schema
-    eval(File.read(SCHEMA_ROOT + "/schema.rb"))
-    if File.exists?(adapter_specific_schema_file)
-      eval(File.read(adapter_specific_schema_file))
-    end
-    assert true
-  end
-
-  def test_drop_and_create_courses_table
-    eval(File.read(SCHEMA_ROOT + "/schema2.rb"))
-    assert true
-  end
-
-  private
-  def adapter_specific_schema_file
-    SCHEMA_ROOT + '/' + ActiveRecord::Base.connection.adapter_name.downcase + '_specific_schema.rb'
-  end
-end
diff --git a/activerecord/test/cases/helper.rb b/activerecord/test/cases/helper.rb
index 05e92433cd..f82784836e 100644
--- a/activerecord/test/cases/helper.rb
+++ b/activerecord/test/cases/helper.rb
@@ -5,6 +5,7 @@ require 'config'
 
 require 'rubygems'
 require 'test/unit'
+require 'stringio'
 gem 'mocha', '>= 0.9.5'
 require 'mocha'
 
@@ -72,3 +73,20 @@ class ActiveSupport::TestCase
     Fixtures.create_fixtures(ActiveSupport::TestCase.fixture_path, table_names, {}, &block)
   end
 end
+
+# silence verbose schema loading
+original_stdout = $stdout
+$stdout = StringIO.new
+
+begin
+  adapter_name = ActiveRecord::Base.connection.adapter_name.downcase
+  adapter_specific_schema_file = SCHEMA_ROOT + "/#{adapter_name}_specific_schema.rb"
+
+  load SCHEMA_ROOT + "/schema.rb"
+
+  if File.exists?(adapter_specific_schema_file)
+    load adapter_specific_schema_file
+  end
+ensure
+  $stdout = original_stdout
+end
diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb
index a776cd974b..4ee0ffe132 100644
--- a/activerecord/test/schema/schema.rb
+++ b/activerecord/test/schema/schema.rb
@@ -1,4 +1,3 @@
-
 ActiveRecord::Schema.define do
   def except(adapter_names_to_exclude)
     unless [adapter_names_to_exclude].flatten.include?(adapter_name)
@@ -500,3 +499,7 @@ ActiveRecord::Schema.define do
     execute "ALTER TABLE fk_test_has_fk ADD CONSTRAINT fk_name FOREIGN KEY (#{quote_column_name 'fk_id'}) REFERENCES #{quote_table_name 'fk_test_has_pk'} (#{quote_column_name 'id'})"
   end
 end
+
+Course.connection.create_table :courses, :force => true do |t|
+  t.column :name, :string, :null => false
+end
diff --git a/activerecord/test/schema/schema2.rb b/activerecord/test/schema/schema2.rb
deleted file mode 100644
index 8527f7ba8f..0000000000
--- a/activerecord/test/schema/schema2.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-ActiveRecord::Schema.define do
-
-  Course.connection.create_table :courses, :force => true do |t|
-    t.column :name, :string, :null => false
-  end
-end
-- 
cgit v1.2.3


From 01d7acd11d631d980497870aad1af42a0c66115c Mon Sep 17 00:00:00 2001
From: Joshua Peek <josh@joshpeek.com>
Date: Sun, 17 May 2009 14:42:36 -0500
Subject: Fix reset_session with ActiveRecord store [#2200 state:resolved]

---
 activerecord/lib/active_record/session_store.rb | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

(limited to 'activerecord')

diff --git a/activerecord/lib/active_record/session_store.rb b/activerecord/lib/active_record/session_store.rb
index 21471da419..9dda3361d8 100644
--- a/activerecord/lib/active_record/session_store.rb
+++ b/activerecord/lib/active_record/session_store.rb
@@ -295,7 +295,7 @@ module ActiveRecord
 
       def set_session(env, sid, session_data)
         Base.silence do
-          record = env[SESSION_RECORD_KEY] ||= find_session(sid)
+          record = get_session_model(env, sid)
           record.data = session_data
           return false unless record.save
 
@@ -309,6 +309,14 @@ module ActiveRecord
 
         return true
       end
+      
+      def get_session_model(env, sid)
+        if env[ENV_SESSION_OPTIONS_KEY][:id].nil?
+          env[SESSION_RECORD_KEY] = find_session(sid)
+        else
+          env[SESSION_RECORD_KEY] ||= find_session(sid)
+        end
+      end
 
       def find_session(id)
         @@session_class.find_by_session_id(id) ||
-- 
cgit v1.2.3


From 27de7f150b57a18d4ccdd274f6f8b621b58108c6 Mon Sep 17 00:00:00 2001
From: Benjamin Floering <floering@ieee.org>
Date: Sun, 17 May 2009 23:35:47 -0700
Subject: Fixed limited eager loading associations with numbers in the name
 [#2668 state:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
---
 activerecord/lib/active_record/associations.rb     | 2 +-
 activerecord/test/cases/associations/eager_test.rb | 4 ++++
 activerecord/test/fixtures/people.yml              | 5 ++++-
 activerecord/test/models/person.rb                 | 1 +
 activerecord/test/schema/schema.rb                 | 1 +
 5 files changed, 11 insertions(+), 2 deletions(-)

(limited to 'activerecord')

diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index c5e4df4950..76726b7845 100755
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -1668,7 +1668,7 @@ module ActiveRecord
 
         def tables_in_string(string)
           return [] if string.blank?
-          string.scan(/([\.a-zA-Z_]+).?\./).flatten
+          string.scan(/([a-zA-Z_][\.\w]+).?\./).flatten
         end
 
         def tables_in_hash(hash)
diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb
index d23f86b700..65049c4f87 100644
--- a/activerecord/test/cases/associations/eager_test.rb
+++ b/activerecord/test/cases/associations/eager_test.rb
@@ -589,6 +589,10 @@ class EagerAssociationTest < ActiveRecord::TestCase
     assert_equal posts(:sti_post_and_comments, :sti_comments), Post.find(:all, :include => [:author, :comments], :conditions => "authors.name = 'David'", :order => 'UPPER(posts.title) DESC, posts.id', :limit => 2, :offset => 1)
   end
 
+  def test_limited_eager_with_numeric_in_association
+    assert_equal people(:david, :susan), Person.find(:all, :include => [:readers, :primary_contact, :number1_fan], :conditions => "number1_fans_people.first_name like 'M%'", :order => 'readers.id', :limit => 2, :offset => 0)
+  end
+
   def test_preload_with_interpolation
     assert_equal [comments(:greetings)], Post.find(posts(:welcome).id, :include => :comments_with_interpolated_conditions).comments_with_interpolated_conditions
   end
diff --git a/activerecord/test/fixtures/people.yml b/activerecord/test/fixtures/people.yml
index 3babb1fe59..123673a2af 100644
--- a/activerecord/test/fixtures/people.yml
+++ b/activerecord/test/fixtures/people.yml
@@ -2,14 +2,17 @@ michael:
   id: 1
   first_name: Michael
   primary_contact_id: 2
+  number1_fan_id: 3
   gender: M
 david:
   id: 2
   first_name: David
   primary_contact_id: 3
+  number1_fan_id: 1
   gender: M
 susan:
   id: 3
   first_name: Susan
   primary_contact_id: 2
-  gender: F
\ No newline at end of file
+  number1_fan_id: 1
+  gender: F
diff --git a/activerecord/test/models/person.rb b/activerecord/test/models/person.rb
index ec2f684a6e..57fa6418f1 100644
--- a/activerecord/test/models/person.rb
+++ b/activerecord/test/models/person.rb
@@ -10,6 +10,7 @@ class Person < ActiveRecord::Base
 
   belongs_to :primary_contact, :class_name => 'Person'
   has_many :agents, :class_name => 'Person', :foreign_key => 'primary_contact_id'
+  belongs_to :number1_fan, :class_name => 'Person'
 
   named_scope :males, :conditions => { :gender => 'M' }
   named_scope :females, :conditions => { :gender => 'F' }
diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb
index 4ee0ffe132..6e8813d8ab 100644
--- a/activerecord/test/schema/schema.rb
+++ b/activerecord/test/schema/schema.rb
@@ -324,6 +324,7 @@ ActiveRecord::Schema.define do
     t.string     :first_name, :null => false
     t.references :primary_contact
     t.string     :gender, :limit => 1
+    t.references :number1_fan
     t.integer    :lock_version, :null => false, :default => 0
   end
 
-- 
cgit v1.2.3