[DRE-commits] [SCM] ruby-activerecord-3.2.git branch, master, updated. debian/3.2.6-5-27-g2ee0c93

Ondřej Surý ondrej at sury.org
Wed May 29 09:06:39 UTC 2013


The following commit has been merged in the master branch:
commit d5e8e0aca5eb860f4007cc2f186079f76fa2a0a5
Author: Ondřej Surý <ondrej at sury.org>
Date:   Fri Oct 12 10:44:51 2012 +0200

    Imported Upstream version 3.2.8

diff --git a/CHANGELOG.md b/CHANGELOG.md
index aa66345..44a58e0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,56 @@
+## Rails 3.2.8 (Aug 9, 2012) ##
+
+*   Do not consider the numeric attribute as changed if the old value is zero and the new value
+    is not a string.
+    Fixes #7237.
+
+    *Rafael Mendonça França*
+
+*   Removes the deprecation of `update_attribute`. *fxn*
+
+*   Reverted the deprecation of `composed_of`. *Rafael Mendonça França*
+
+*   Reverted the deprecation of `*_sql` association options. They will
+    be deprecated in 4.0 instead. *Jon Leighton*
+
+*   Do not eager load AR session store. ActiveRecord::SessionStore depends on the abstract store
+    in Action Pack. Eager loading this class would break client code that eager loads Active Record
+    standalone.
+    Fixes #7160
+
+    *Xavier Noria*
+
+*   Do not set RAILS_ENV to "development" when using `db:test:prepare` and related rake tasks.
+    This was causing the truncation of the development database data when using RSpec.
+    Fixes #7175.
+
+    *Rafael Mendonça França*
+
+## Rails 3.2.7 (Jul 26, 2012) ##
+
+*   `:finder_sql` and `:counter_sql` options on collection associations
+    are deprecated. Please transition to using scopes.
+
+    *Jon Leighton*
+
+*   `:insert_sql` and `:delete_sql` options on `has_and_belongs_to_many`
+    associations are deprecated. Please transition to using `has_many
+    :through`
+
+    *Jon Leighton*
+
+*   `composed_of` has been deprecated. You'll have to write your own accessor
+    and mutator methods if you'd like to use value objects to represent some
+    portion of your models.
+
+    *Steve Klabnik*
+
+*   `update_attribute` has been deprecated. Use `update_column` if
+    you want to bypass mass-assignment protection, validations, callbacks,
+    and touching of updated_at. Otherwise please use `update_attributes`.
+
+    *Steve Klabnik*
+
 ## Rails 3.2.6 (Jun 12, 2012) ##
 
 *   protect against the nesting of hashes changing the
diff --git a/lib/active_record.rb b/lib/active_record.rb
index 2463f39..14f2715 100644
--- a/lib/active_record.rb
+++ b/lib/active_record.rb
@@ -31,6 +31,16 @@ require 'active_record/version'
 module ActiveRecord
   extend ActiveSupport::Autoload
 
+  # ActiveRecord::SessionStore depends on the abstract store in Action Pack.
+  # Eager loading this class would break client code that eager loads Active
+  # Record standalone.
+  #
+  # Note that the Rails application generator creates an initializer specific
+  # for setting the session store. Thus, albeit in theory this autoload would
+  # not be thread-safe, in practice it is because if the application uses this
+  # session store its autoload happens at boot time.
+  autoload :SessionStore
+
   eager_autoload do
     autoload :ActiveRecordError, 'active_record/errors'
     autoload :ConnectionNotEstablished, 'active_record/errors'
@@ -81,7 +91,6 @@ module ActiveRecord
     autoload :SchemaDumper
     autoload :Scoping
     autoload :Serialization
-    autoload :SessionStore
     autoload :Store
     autoload :Timestamp
     autoload :Transactions
diff --git a/lib/active_record/associations/has_one_association.rb b/lib/active_record/associations/has_one_association.rb
index 2131edb..f0d1120 100644
--- a/lib/active_record/associations/has_one_association.rb
+++ b/lib/active_record/associations/has_one_association.rb
@@ -36,7 +36,7 @@ module ActiveRecord
             when :destroy
               target.destroy
             when :nullify
-              target.update_attribute(reflection.foreign_key, nil)
+              target.update_column(reflection.foreign_key, nil)
           end
         end
       end
diff --git a/lib/active_record/attribute_assignment.rb b/lib/active_record/attribute_assignment.rb
index bf9fe70..ca5f7b9 100644
--- a/lib/active_record/attribute_assignment.rb
+++ b/lib/active_record/attribute_assignment.rb
@@ -64,7 +64,7 @@ module ActiveRecord
     #   user.name       # => "Josh"
     #   user.is_admin?  # => true
     def assign_attributes(new_attributes, options = {})
-      return unless new_attributes
+      return if new_attributes.blank?
 
       attributes = new_attributes.stringify_keys
       multi_parameter_attributes = []
diff --git a/lib/active_record/attribute_methods/dirty.rb b/lib/active_record/attribute_methods/dirty.rb
index f61e016..ed863a9 100644
--- a/lib/active_record/attribute_methods/dirty.rb
+++ b/lib/active_record/attribute_methods/dirty.rb
@@ -79,11 +79,8 @@ module ActiveRecord
 
       def field_changed?(attr, old, value)
         if column = column_for_attribute(attr)
-          if column.number? && column.null && (old.nil? || old == 0) && value.blank?
-            # For nullable numeric columns, NULL gets stored in database for blank (i.e. '') values.
-            # Hence we don't record it as a change if the value changes from nil to ''.
-            # If an old value of 0 is set to '' we want this to get changed to nil as otherwise it'll
-            # be typecast back to 0 (''.to_i => 0)
+          if column.number? && (changes_from_nil_to_empty_string?(column, old, value) ||
+                                changes_from_zero_to_string?(old, value))
             value = nil
           else
             value = column.type_cast(value)
@@ -96,6 +93,19 @@ module ActiveRecord
       def clone_with_time_zone_conversion_attribute?(attr, old)
         old.class.name == "Time" && time_zone_aware_attributes && !self.skip_time_zone_conversion_for_attributes.include?(attr.to_sym)
       end
+
+      def changes_from_nil_to_empty_string?(column, old, value)
+        # For nullable numeric columns, NULL gets stored in database for blank (i.e. '') values.
+        # Hence we don't record it as a change if the value changes from nil to ''.
+        # If an old value of 0 is set to '' we want this to get changed to nil as otherwise it'll
+        # be typecast back to 0 (''.to_i => 0)
+        column.null && (old.nil? || old == 0) && value.blank?
+      end
+
+      def changes_from_zero_to_string?(old, value)
+        # For columns with old 0 and value non-empty string
+        old == 0 && value.is_a?(String) && value.present? && value != '0'
+      end
     end
   end
 end
diff --git a/lib/active_record/autosave_association.rb b/lib/active_record/autosave_association.rb
index c86eaba..e1499fc 100644
--- a/lib/active_record/autosave_association.rb
+++ b/lib/active_record/autosave_association.rb
@@ -332,25 +332,31 @@ module ActiveRecord
 
         if records = associated_records_to_validate_or_save(association, @new_record_before_save, autosave)
           begin
-          records.each do |record|
-            next if record.destroyed?
+            records_to_destroy = []
+
+            records.each do |record|
+              next if record.destroyed?
+
+              saved = true
+
+              if autosave && record.marked_for_destruction?
+                records_to_destroy << record
+              elsif autosave != false && (@new_record_before_save || record.new_record?)
+                if autosave
+                  saved = association.insert_record(record, false)
+                else
+                  association.insert_record(record) unless reflection.nested?
+                end
+              elsif autosave
+                saved = record.save(:validate => false)
+              end
 
-            saved = true
+              raise ActiveRecord::Rollback unless saved
+            end
 
-            if autosave && record.marked_for_destruction?
+            records_to_destroy.each do |record|
               association.proxy.destroy(record)
-            elsif autosave != false && (@new_record_before_save || record.new_record?)
-              if autosave
-                saved = association.insert_record(record, false)
-              else
-                association.insert_record(record) unless reflection.nested?
-              end
-            elsif autosave
-              saved = record.save(:validate => false)
             end
-
-            raise ActiveRecord::Rollback unless saved
-          end
           rescue
             records.each {|x| IdentityMap.remove(x) } if IdentityMap.enabled?
             raise
diff --git a/lib/active_record/base.rb b/lib/active_record/base.rb
index c6f2102..b51bb5c 100644
--- a/lib/active_record/base.rb
+++ b/lib/active_record/base.rb
@@ -697,9 +697,9 @@ module ActiveRecord #:nodoc:
     include Scoping
     extend DynamicMatchers
     include Sanitization
-    include Integration
     include AttributeAssignment
     include ActiveModel::Conversion
+    include Integration
     include Validations
     extend CounterCache
     include Locking::Optimistic, Locking::Pessimistic
diff --git a/lib/active_record/connection_adapters/abstract/connection_specification.rb b/lib/active_record/connection_adapters/abstract/connection_specification.rb
index 7145dc0..6c8a102 100644
--- a/lib/active_record/connection_adapters/abstract/connection_specification.rb
+++ b/lib/active_record/connection_adapters/abstract/connection_specification.rb
@@ -1,3 +1,5 @@
+require 'uri'
+
 module ActiveRecord
   class Base
     class ConnectionSpecification #:nodoc:
diff --git a/lib/active_record/connection_adapters/abstract/query_cache.rb b/lib/active_record/connection_adapters/abstract/query_cache.rb
index 06e4c7a..6b6f926 100644
--- a/lib/active_record/connection_adapters/abstract/query_cache.rb
+++ b/lib/active_record/connection_adapters/abstract/query_cache.rb
@@ -56,7 +56,7 @@ module ActiveRecord
       end
 
       def select_all(arel, name = nil, binds = [])
-        if @query_cache_enabled
+        if @query_cache_enabled && !locked?(arel)
           sql = to_sql(arel, binds)
           cache_sql(sql, binds) { super(sql, name, binds) }
         else
@@ -77,6 +77,14 @@ module ActiveRecord
 
           result.collect { |row| row.dup }
         end
+
+        def locked?(arel)
+          if arel.respond_to?(:locked)
+            arel.locked
+          else
+            false
+          end
+        end
     end
   end
 end
diff --git a/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
index 88f82b5..abccc3a 100644
--- a/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
+++ b/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
@@ -72,6 +72,8 @@ module ActiveRecord
           when /^mediumint/i; 3
           when /^smallint/i;  2
           when /^tinyint/i;   1
+          when /^enum\((.+)\)/i
+            $1.split(',').map{|enum| enum.strip.length - 2}.max
           else
             super
           end
@@ -325,7 +327,7 @@ module ActiveRecord
         select_all(sql).map { |table|
           table.delete('Table_type')
           sql = "SHOW CREATE TABLE #{quote_table_name(table.to_a.first.last)}"
-          exec_without_stmt(sql).first['Create Table'] + ";\n\n"
+          exec_query(sql).first['Create Table'] + ";\n\n"
         }.join
       end
 
diff --git a/lib/active_record/connection_adapters/mysql_adapter.rb b/lib/active_record/connection_adapters/mysql_adapter.rb
index f092ede..c132692 100644
--- a/lib/active_record/connection_adapters/mysql_adapter.rb
+++ b/lib/active_record/connection_adapters/mysql_adapter.rb
@@ -214,7 +214,7 @@ module ActiveRecord
 
       def select_rows(sql, name = nil)
         @connection.query_with_result = true
-        rows = exec_without_stmt(sql, name).rows
+        rows = exec_query(sql, name).rows
         @connection.more_results && @connection.next_result    # invoking stored procedures with CLIENT_MULTI_RESULTS requires this to tidy up else connection will be dropped
         rows
       end
@@ -282,11 +282,19 @@ module ActiveRecord
       end
 
       def exec_query(sql, name = 'SQL', binds = [])
-        log(sql, name, binds) do
-          exec_stmt(sql, name, binds) do |cols, stmt|
-            ActiveRecord::Result.new(cols, stmt.to_a) if cols
-          end
+        # If the configuration sets prepared_statements:false, binds will
+        # always be empty, since the bind variables will have been already
+        # substituted and removed from binds by BindVisitor, so this will
+        # effectively disable prepared statement usage completely.
+        if binds.empty?
+          result_set, affected_rows = exec_without_stmt(sql, name)
+        else
+          result_set, affected_rows = exec_stmt(sql, name, binds)
         end
+
+        yield affected_rows if block_given?
+
+        result_set
       end
 
       def last_inserted_id(result)
@@ -298,15 +306,17 @@ module ActiveRecord
         # statement API. For those queries, we need to use this method. :'(
         log(sql, name) do
           result = @connection.query(sql)
-          cols = []
-          rows = []
+          affected_rows = @connection.affected_rows
 
           if result
             cols = result.fetch_fields.map { |field| field.name }
-            rows = result.to_a
+            result_set = ActiveRecord::Result.new(cols, result.to_a)
             result.free
+          else
+            result_set = ActiveRecord::Result.new([], [])
           end
-          ActiveRecord::Result.new(cols, rows)
+
+          [result_set, affected_rows]
         end
       end
 
@@ -324,16 +334,18 @@ module ActiveRecord
       alias :create :insert_sql
 
       def exec_delete(sql, name, binds)
-        log(sql, name, binds) do
-          exec_stmt(sql, name, binds) do |cols, stmt|
-            stmt.affected_rows
-          end
+        affected_rows = 0
+
+        exec_query(sql, name, binds) do |n|
+          affected_rows = n
         end
+
+        affected_rows
       end
       alias :exec_update :exec_delete
 
       def begin_db_transaction #:nodoc:
-        exec_without_stmt "BEGIN"
+        exec_query "BEGIN"
       rescue Mysql::Error
         # Transactions aren't supported
       end
@@ -342,41 +354,44 @@ module ActiveRecord
 
       def exec_stmt(sql, name, binds)
         cache = {}
-        if binds.empty?
-          stmt = @connection.prepare(sql)
-        else
-          cache = @statements[sql] ||= {
-            :stmt => @connection.prepare(sql)
-          }
-          stmt = cache[:stmt]
-        end
+        log(sql, name, binds) do
+          if binds.empty?
+            stmt = @connection.prepare(sql)
+          else
+            cache = @statements[sql] ||= {
+              :stmt => @connection.prepare(sql)
+            }
+            stmt = cache[:stmt]
+          end
 
-        begin
-          stmt.execute(*binds.map { |col, val| type_cast(val, col) })
-        rescue Mysql::Error => e
-          # Older versions of MySQL leave the prepared statement in a bad
-          # place when an error occurs. To support older mysql versions, we
-          # need to close the statement and delete the statement from the
-          # cache.
-          stmt.close
-          @statements.delete sql
-          raise e
-        end
+          begin
+            stmt.execute(*binds.map { |col, val| type_cast(val, col) })
+          rescue Mysql::Error => e
+            # Older versions of MySQL leave the prepared statement in a bad
+            # place when an error occurs. To support older mysql versions, we
+            # need to close the statement and delete the statement from the
+            # cache.
+            stmt.close
+            @statements.delete sql
+            raise e
+          end
 
-        cols = nil
-        if metadata = stmt.result_metadata
-          cols = cache[:cols] ||= metadata.fetch_fields.map { |field|
-            field.name
-          }
-        end
+          cols = nil
+          if metadata = stmt.result_metadata
+            cols = cache[:cols] ||= metadata.fetch_fields.map { |field|
+              field.name
+            }
+          end
 
-        result = yield [cols, stmt]
+          result_set = ActiveRecord::Result.new(cols, stmt.to_a) if cols
+          affected_rows = stmt.affected_rows
 
-        stmt.result_metadata.free if cols
-        stmt.free_result
-        stmt.close if binds.empty?
+          stmt.result_metadata.free if cols
+          stmt.free_result
+          stmt.close if binds.empty?
 
-        result
+          [result_set, affected_rows]
+        end
       end
 
       def connect
diff --git a/lib/active_record/connection_adapters/postgresql_adapter.rb b/lib/active_record/connection_adapters/postgresql_adapter.rb
index 822f8f7..cd56578 100644
--- a/lib/active_record/connection_adapters/postgresql_adapter.rb
+++ b/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -1005,12 +1005,19 @@ module ActiveRecord
       end
 
       # Renames a table.
+      # Also renames a table's primary key sequence if the sequence name matches the
+      # Active Record default.
       #
       # Example:
       #   rename_table('octopuses', 'octopi')
       def rename_table(name, new_name)
         clear_cache!
         execute "ALTER TABLE #{quote_table_name(name)} RENAME TO #{quote_table_name(new_name)}"
+        pk, seq = pk_and_sequence_for(new_name)
+        if seq == "#{name}_#{pk}_seq"
+          new_seq = "#{new_name}_#{pk}_seq"
+          execute "ALTER TABLE #{quote_table_name(seq)} RENAME TO #{quote_table_name(new_seq)}"
+        end
       end
 
       # Adds a new column to the named table.
diff --git a/lib/active_record/migration.rb b/lib/active_record/migration.rb
index e668659..b4b4667 100644
--- a/lib/active_record/migration.rb
+++ b/lib/active_record/migration.rb
@@ -232,7 +232,7 @@ module ActiveRecord
   #       add_column :people, :salary, :integer
   #       Person.reset_column_information
   #       Person.all.each do |p|
-  #         p.update_attribute :salary, SalaryCalculator.compute(p)
+  #         p.update_column :salary, SalaryCalculator.compute(p)
   #       end
   #     end
   #   end
@@ -252,7 +252,7 @@ module ActiveRecord
   #     ...
   #     say_with_time "Updating salaries..." do
   #       Person.all.each do |p|
-  #         p.update_attribute :salary, SalaryCalculator.compute(p)
+  #         p.update_column :salary, SalaryCalculator.compute(p)
   #       end
   #     end
   #     ...
diff --git a/lib/active_record/persistence.rb b/lib/active_record/persistence.rb
index 038355d..d6249db 100644
--- a/lib/active_record/persistence.rb
+++ b/lib/active_record/persistence.rb
@@ -174,6 +174,9 @@ module ActiveRecord
     # * updated_at/updated_on column is updated if that column is available.
     # * Updates all the attributes that are dirty in this object.
     #
+    # This method has been deprecated in favor of <tt>update_column</tt> due to
+    # its similarity with <tt>update_attributes</tt>.
+    #
     def update_attribute(name, value)
       name = name.to_s
       raise ActiveRecordError, "#{name} is marked as readonly" if self.class.readonly_attributes.include?(name)
@@ -239,7 +242,7 @@ module ActiveRecord
     # Saving is not subjected to validation checks. Returns +true+ if the
     # record could be saved.
     def increment!(attribute, by = 1)
-      increment(attribute, by).update_attribute(attribute, self[attribute])
+      increment(attribute, by).update_column(attribute, self[attribute])
     end
 
     # Initializes +attribute+ to zero if +nil+ and subtracts the value passed as +by+ (default is 1).
@@ -256,7 +259,7 @@ module ActiveRecord
     # Saving is not subjected to validation checks. Returns +true+ if the
     # record could be saved.
     def decrement!(attribute, by = 1)
-      decrement(attribute, by).update_attribute(attribute, self[attribute])
+      decrement(attribute, by).update_column(attribute, self[attribute])
     end
 
     # Assigns to +attribute+ the boolean opposite of <tt>attribute?</tt>. So
@@ -273,7 +276,7 @@ module ActiveRecord
     # Saving is not subjected to validation checks. Returns +true+ if the
     # record could be saved.
     def toggle!(attribute)
-      toggle(attribute).update_attribute(attribute, self[attribute])
+      toggle(attribute).update_column(attribute, self[attribute])
     end
 
     # Reloads the attributes of this object from the database.
diff --git a/lib/active_record/railties/databases.rake b/lib/active_record/railties/databases.rake
index abdd935..79032fe 100644
--- a/lib/active_record/railties/databases.rake
+++ b/lib/active_record/railties/databases.rake
@@ -2,7 +2,7 @@ require 'active_support/core_ext/object/inclusion'
 require 'active_record'
 
 db_namespace = namespace :db do
-  task :load_config => :rails_env do
+  task :load_config do
     ActiveRecord::Base.configurations = Rails.application.config.database_configuration
     ActiveRecord::Migrator.migrations_paths = Rails.application.paths['db/migrate'].to_a
 
@@ -36,7 +36,7 @@ db_namespace = namespace :db do
   end
 
   desc 'Create the database from config/database.yml for the current Rails.env (use db:create:all to create all dbs in the config)'
-  task :create => :load_config do
+  task :create => [:load_config, :rails_env] do
     configs_for_environment.each { |config| create_database(config) }
     ActiveRecord::Base.establish_connection(configs_for_environment.first)
   end
@@ -134,7 +134,7 @@ db_namespace = namespace :db do
   end
 
   desc 'Drops the database for the current Rails.env (use db:drop:all to drop all databases)'
-  task :drop => :load_config do
+  task :drop => [:load_config, :rails_env] do
     configs_for_environment.each { |config| drop_database_and_rescue(config) }
   end
 
@@ -201,7 +201,7 @@ db_namespace = namespace :db do
 
     desc 'Display status of migrations'
     task :status => [:environment, :load_config] do
-      config = ActiveRecord::Base.configurations[Rails.env || 'development']
+      config = ActiveRecord::Base.configurations[Rails.env]
       ActiveRecord::Base.establish_connection(config)
       unless ActiveRecord::Base.connection.table_exists?(ActiveRecord::Migrator.schema_migrations_table_name)
         puts 'Schema migrations table does not exist yet.'
@@ -247,14 +247,14 @@ db_namespace = namespace :db do
   end
 
   # desc 'Drops and recreates the database from db/schema.rb for the current environment and loads the seeds.'
-  task :reset => :environment do
+  task :reset => [:environment, :load_config] do
     db_namespace["drop"].invoke
     db_namespace["setup"].invoke
   end
 
   # desc "Retrieves the charset for the current environment's database"
-  task :charset => :environment do
-    config = ActiveRecord::Base.configurations[Rails.env || 'development']
+  task :charset => [:environment, :load_config] do
+    config = ActiveRecord::Base.configurations[Rails.env]
     case config['adapter']
     when /mysql/
       ActiveRecord::Base.establish_connection(config)
@@ -271,8 +271,8 @@ db_namespace = namespace :db do
   end
 
   # desc "Retrieves the collation for the current environment's database"
-  task :collation => :environment do
-    config = ActiveRecord::Base.configurations[Rails.env || 'development']
+  task :collation => [:environment, :load_config] do
+    config = ActiveRecord::Base.configurations[Rails.env]
     case config['adapter']
     when /mysql/
       ActiveRecord::Base.establish_connection(config)
@@ -283,12 +283,12 @@ db_namespace = namespace :db do
   end
 
   desc 'Retrieves the current schema version number'
-  task :version => :environment do
+  task :version => [:environment, :load_config] do
     puts "Current version: #{ActiveRecord::Migrator.current_version}"
   end
 
   # desc "Raises an error if there are pending migrations"
-  task :abort_if_pending_migrations => :environment do
+  task :abort_if_pending_migrations => [:environment, :load_config] do
     pending_migrations = ActiveRecord::Migrator.new(:up, ActiveRecord::Migrator.migrations_paths).pending_migrations
 
     if pending_migrations.any?
@@ -311,7 +311,7 @@ db_namespace = namespace :db do
 
   namespace :fixtures do
     desc "Load fixtures into the current environment's database. Load specific fixtures using FIXTURES=x,y. Load from subdirectory in test/fixtures using FIXTURES_DIR=z. Specify an alternative path (eg. spec/fixtures) using FIXTURES_PATH=spec/fixtures."
-    task :load => :environment do
+    task :load => [:environment, :load_config] do
       require 'active_record/fixtures'
 
       ActiveRecord::Base.establish_connection(Rails.env)
@@ -324,7 +324,7 @@ db_namespace = namespace :db do
     end
 
     # desc "Search for a fixture given a LABEL or ID. Specify an alternative path (eg. spec/fixtures) using FIXTURES_PATH=spec/fixtures."
-    task :identify => :environment do
+    task :identify => [:environment, :load_config] do
       require 'active_record/fixtures'
 
       label, id = ENV['LABEL'], ENV['ID']
@@ -360,7 +360,7 @@ db_namespace = namespace :db do
     end
 
     desc 'Load a schema.rb file into the database'
-    task :load => :environment do
+    task :load => [:environment, :load_config] do
       file = ENV['SCHEMA'] || "#{Rails.root}/db/schema.rb"
       if File.exists?(file)
         load(file)
@@ -376,7 +376,7 @@ db_namespace = namespace :db do
 
   namespace :structure do
     desc 'Dump the database structure to db/structure.sql. Specify another file with DB_STRUCTURE=db/my_structure.sql'
-    task :dump => :environment do
+    task :dump => [:environment, :load_config] do
       abcs = ActiveRecord::Base.configurations
       filename = ENV['DB_STRUCTURE'] || File.join(Rails.root, "db", "structure.sql")
       case abcs[Rails.env]['adapter']
@@ -459,7 +459,7 @@ db_namespace = namespace :db do
           db_namespace["test:load_schema"].invoke
         when :sql
           db_namespace["test:load_structure"].invoke
-        end
+      end
     end
 
     # desc "Recreate the test database from an existent structure.sql file"
@@ -486,7 +486,7 @@ db_namespace = namespace :db do
     task :clone_structure => [ "db:structure:dump", "db:test:load_structure" ]
 
     # desc "Empty the test database"
-    task :purge => :environment do
+    task :purge => [:environment, :load_config] do
       abcs = ActiveRecord::Base.configurations
       case abcs['test']['adapter']
       when /mysql/
@@ -528,7 +528,7 @@ db_namespace = namespace :db do
 
   namespace :sessions do
     # desc "Creates a sessions migration for use with ActiveRecord::SessionStore"
-    task :create => :environment do
+    task :create => [:environment, :load_config] do
       raise 'Task unavailable to this database (no migration support)' unless ActiveRecord::Base.connection.supports_migrations?
       Rails.application.load_generators
       require 'rails/generators/rails/session_migration/session_migration_generator'
@@ -536,7 +536,7 @@ db_namespace = namespace :db do
     end
 
     # desc "Clear the sessions table"
-    task :clear => :environment do
+    task :clear => [:environment, :load_config] do
       ActiveRecord::Base.connection.execute "DELETE FROM #{session_table_name}"
     end
   end
@@ -564,7 +564,7 @@ namespace :railties do
         puts "Copied migration #{migration.basename} from #{name}"
       end
 
-      ActiveRecord::Migration.copy( ActiveRecord::Migrator.migrations_paths.first, railties,
+      ActiveRecord::Migration.copy(ActiveRecord::Migrator.migrations_paths.first, railties,
                                     :on_skip => on_skip, :on_copy => on_copy)
     end
   end
diff --git a/lib/active_record/relation/calculations.rb b/lib/active_record/relation/calculations.rb
index 0d60810..802059d 100644
--- a/lib/active_record/relation/calculations.rb
+++ b/lib/active_record/relation/calculations.rb
@@ -244,10 +244,16 @@ module ActiveRecord
     end
 
     def execute_grouped_calculation(operation, column_name, distinct) #:nodoc:
-      group_attr      = @group_values
-      association     = @klass.reflect_on_association(group_attr.first.to_sym)
-      associated      = group_attr.size == 1 && association && association.macro == :belongs_to # only count belongs_to associations
-      group_fields  = Array(associated ? association.foreign_key : group_attr)
+      group_attrs = @group_values
+
+      if group_attrs.first.respond_to?(:to_sym)
+        association  = @klass.reflect_on_association(group_attrs.first.to_sym)
+        associated   = group_attrs.size == 1 && association && association.macro == :belongs_to # only count belongs_to associations
+        group_fields = Array(associated ? association.foreign_key : group_attrs)
+      else
+        group_fields = group_attrs
+      end
+
       group_aliases = group_fields.map { |field| column_alias_for(field) }
       group_columns = group_aliases.zip(group_fields).map { |aliaz,field|
         [aliaz, column_for(field)]
@@ -270,10 +276,14 @@ module ActiveRecord
       select_values += @select_values unless @having_values.empty?
 
       select_values.concat group_fields.zip(group_aliases).map { |field,aliaz|
-        "#{field} AS #{aliaz}"
+        if field.respond_to?(:as)
+          field.as(aliaz)
+        else
+          "#{field} AS #{aliaz}"
+        end
       }
 
-      relation = except(:group).group(group.join(','))
+      relation = except(:group).group(group)
       relation.select_values = select_values
 
       calculated_data = @klass.connection.select_all(relation)
@@ -285,10 +295,10 @@ module ActiveRecord
       end
 
       ActiveSupport::OrderedHash[calculated_data.map do |row|
-        key   = group_columns.map { |aliaz, column|
+        key = group_columns.map { |aliaz, column|
           type_cast_calculated_value(row[aliaz], column)
         }
-        key   = key.first if key.size == 1
+        key = key.first if key.size == 1
         key = key_records[key] if associated
         [key, type_cast_calculated_value(row[aggregate_alias], column_for(column_name), operation)]
       end]
@@ -303,6 +313,7 @@ module ActiveRecord
     #   column_alias_for("count(*)")                 # => "count_all"
     #   column_alias_for("count", "id")              # => "count_id"
     def column_alias_for(*keys)
+      keys.map! {|k| k.respond_to?(:to_sql) ? k.to_sql : k}
       table_name = keys.join(' ')
       table_name.downcase!
       table_name.gsub!(/\*/, 'all')
@@ -314,7 +325,7 @@ module ActiveRecord
     end
 
     def column_for(field)
-      field_name = field.to_s.split('.').last
+      field_name = field.respond_to?(:name) ? field.name.to_s : field.to_s.split('.').last
       @klass.columns.detect { |c| c.name.to_s == field_name }
     end
 
diff --git a/lib/active_record/schema_dumper.rb b/lib/active_record/schema_dumper.rb
index 6dc07a6..f4287aa 100644
--- a/lib/active_record/schema_dumper.rb
+++ b/lib/active_record/schema_dumper.rb
@@ -70,8 +70,8 @@ HEADER
         @connection.tables.sort.each do |tbl|
           next if ['schema_migrations', ignore_tables].flatten.any? do |ignored|
             case ignored
-            when String; tbl == ignored
-            when Regexp; tbl =~ ignored
+            when String; remove_prefix_and_suffix(tbl) == ignored
+            when Regexp; remove_prefix_and_suffix(tbl) =~ ignored
             else
               raise StandardError, 'ActiveRecord::SchemaDumper.ignore_tables accepts an array of String and / or Regexp values.'
             end
@@ -92,7 +92,7 @@ HEADER
             pk = @connection.primary_key(table)
           end
 
-          tbl.print "  create_table #{table.inspect}"
+          tbl.print "  create_table #{remove_prefix_and_suffix(table).inspect}"
           if columns.detect { |c| c.name == pk }
             if pk != 'id'
               tbl.print %Q(, :primary_key => "#{pk}")
@@ -181,7 +181,7 @@ HEADER
         if (indexes = @connection.indexes(table)).any?
           add_index_statements = indexes.map do |index|
             statement_parts = [
-              ('add_index ' + index.table.inspect),
+              ('add_index ' + remove_prefix_and_suffix(index.table).inspect),
               index.columns.inspect,
               (':name => ' + index.name.inspect),
             ]
@@ -200,5 +200,9 @@ HEADER
           stream.puts
         end
       end
+
+      def remove_prefix_and_suffix(table)
+        table.gsub(/^(#{ActiveRecord::Base.table_name_prefix})(.+)(#{ActiveRecord::Base.table_name_suffix})$/,  "\\2")
+      end
   end
 end
diff --git a/lib/active_record/session_store.rb b/lib/active_record/session_store.rb
index 1029bed..7e8adb7 100644
--- a/lib/active_record/session_store.rb
+++ b/lib/active_record/session_store.rb
@@ -1,3 +1,5 @@
+require 'action_dispatch/middleware/session/abstract_store'
+
 module ActiveRecord
   # = Active Record Session Store
   #
diff --git a/lib/active_record/version.rb b/lib/active_record/version.rb
index 43fc292..0f91199 100644
--- a/lib/active_record/version.rb
+++ b/lib/active_record/version.rb
@@ -2,7 +2,7 @@ module ActiveRecord
   module VERSION #:nodoc:
     MAJOR = 3
     MINOR = 2
-    TINY  = 6
+    TINY  = 8
     PRE   = nil
 
     STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
diff --git a/metadata.yml b/metadata.yml
index 1f9ab56..333ff7a 100644
--- a/metadata.yml
+++ b/metadata.yml
@@ -1,95 +1,89 @@
---- !ruby/object:Gem::Specification 
+--- !ruby/object:Gem::Specification
 name: activerecord
-version: !ruby/object:Gem::Version 
-  hash: 3
+version: !ruby/object:Gem::Version
+  version: 3.2.8
   prerelease: 
-  segments: 
-  - 3
-  - 2
-  - 6
-  version: 3.2.6
 platform: ruby
-authors: 
+authors:
 - David Heinemeier Hansson
 autorequire: 
 bindir: bin
 cert_chain: []
-
-date: 2012-06-12 00:00:00 Z
-dependencies: 
-- !ruby/object:Gem::Dependency 
+date: 2012-08-09 00:00:00.000000000 Z
+dependencies:
+- !ruby/object:Gem::Dependency
   name: activesupport
-  prerelease: false
-  requirement: &id001 !ruby/object:Gem::Requirement 
+  requirement: !ruby/object:Gem::Requirement
     none: false
-    requirements: 
-    - - "="
-      - !ruby/object:Gem::Version 
-        hash: 3
-        segments: 
-        - 3
-        - 2
-        - 6
-        version: 3.2.6
+    requirements:
+    - - '='
+      - !ruby/object:Gem::Version
+        version: 3.2.8
   type: :runtime
-  version_requirements: *id001
-- !ruby/object:Gem::Dependency 
-  name: activemodel
   prerelease: false
-  requirement: &id002 !ruby/object:Gem::Requirement 
+  version_requirements: !ruby/object:Gem::Requirement
+    none: false
+    requirements:
+    - - '='
+      - !ruby/object:Gem::Version
+        version: 3.2.8
+- !ruby/object:Gem::Dependency
+  name: activemodel
+  requirement: !ruby/object:Gem::Requirement
     none: false
-    requirements: 
-    - - "="
-      - !ruby/object:Gem::Version 
-        hash: 3
-        segments: 
-        - 3
-        - 2
-        - 6
-        version: 3.2.6
+    requirements:
+    - - '='
+      - !ruby/object:Gem::Version
+        version: 3.2.8
   type: :runtime
-  version_requirements: *id002
-- !ruby/object:Gem::Dependency 
-  name: arel
   prerelease: false
-  requirement: &id003 !ruby/object:Gem::Requirement 
+  version_requirements: !ruby/object:Gem::Requirement
+    none: false
+    requirements:
+    - - '='
+      - !ruby/object:Gem::Version
+        version: 3.2.8
+- !ruby/object:Gem::Dependency
+  name: arel
+  requirement: !ruby/object:Gem::Requirement
     none: false
-    requirements: 
+    requirements:
     - - ~>
-      - !ruby/object:Gem::Version 
-        hash: 3
-        segments: 
-        - 3
-        - 0
-        - 2
+      - !ruby/object:Gem::Version
         version: 3.0.2
   type: :runtime
-  version_requirements: *id003
-- !ruby/object:Gem::Dependency 
-  name: tzinfo
   prerelease: false
-  requirement: &id004 !ruby/object:Gem::Requirement 
+  version_requirements: !ruby/object:Gem::Requirement
     none: false
-    requirements: 
+    requirements:
     - - ~>
-      - !ruby/object:Gem::Version 
-        hash: 41
-        segments: 
-        - 0
-        - 3
-        - 29
+      - !ruby/object:Gem::Version
+        version: 3.0.2
+- !ruby/object:Gem::Dependency
+  name: tzinfo
+  requirement: !ruby/object:Gem::Requirement
+    none: false
+    requirements:
+    - - ~>
+      - !ruby/object:Gem::Version
         version: 0.3.29
   type: :runtime
-  version_requirements: *id004
-description: Databases on Rails. Build a persistent domain model by mapping database tables to Ruby classes. Strong conventions for associations, validations, aggregations, migrations, and testing come baked-in.
+  prerelease: false
+  version_requirements: !ruby/object:Gem::Requirement
+    none: false
+    requirements:
+    - - ~>
+      - !ruby/object:Gem::Version
+        version: 0.3.29
+description: Databases on Rails. Build a persistent domain model by mapping database
+  tables to Ruby classes. Strong conventions for associations, validations, aggregations,
+  migrations, and testing come baked-in.
 email: david at loudthinking.com
 executables: []
-
 extensions: []
-
-extra_rdoc_files: 
+extra_rdoc_files:
 - README.rdoc
-files: 
+files:
 - CHANGELOG.md
 - MIT-LICENSE
 - README.rdoc
@@ -241,39 +235,31 @@ files:
 - lib/rails/generators/active_record.rb
 homepage: http://www.rubyonrails.org
 licenses: []
-
 post_install_message: 
-rdoc_options: 
+rdoc_options:
 - --main
 - README.rdoc
-require_paths: 
+require_paths:
 - lib
-required_ruby_version: !ruby/object:Gem::Requirement 
+required_ruby_version: !ruby/object:Gem::Requirement
   none: false
-  requirements: 
-  - - ">="
-    - !ruby/object:Gem::Version 
-      hash: 57
-      segments: 
-      - 1
-      - 8
-      - 7
+  requirements:
+  - - ! '>='
+    - !ruby/object:Gem::Version
       version: 1.8.7
-required_rubygems_version: !ruby/object:Gem::Requirement 
+required_rubygems_version: !ruby/object:Gem::Requirement
   none: false
-  requirements: 
-  - - ">="
-    - !ruby/object:Gem::Version 
-      hash: 3
-      segments: 
+  requirements:
+  - - ! '>='
+    - !ruby/object:Gem::Version
+      version: '0'
+      segments:
       - 0
-      version: "0"
+      hash: -3836965031648198362
 requirements: []
-
 rubyforge_project: 
-rubygems_version: 1.8.22
+rubygems_version: 1.8.24
 signing_key: 
 specification_version: 3
 summary: Object-relational mapper framework (part of Rails).
 test_files: []
-

-- 
ruby-activerecord-3.2.git



More information about the Pkg-ruby-extras-commits mailing list