diff options
author | José Valim <jose.valim@gmail.com> | 2009-11-11 08:16:25 -0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2009-11-11 08:16:25 -0200 |
commit | 01ae99c681d31803f3a29f8305c9a041aa456660 (patch) | |
tree | 7fdb9e32b743aeb254854371349cecfd2499defa /activerecord | |
parent | d002826e54415a340e55fdbf363d005faebf8fc5 (diff) | |
parent | fca32eb6c5b41e4f19a25b7b246c4a8a3d763667 (diff) | |
download | rails-01ae99c681d31803f3a29f8305c9a041aa456660.tar.gz rails-01ae99c681d31803f3a29f8305c9a041aa456660.tar.bz2 rails-01ae99c681d31803f3a29f8305c9a041aa456660.zip |
Merge branch 'master' of git://github.com/rails/rails
Diffstat (limited to 'activerecord')
19 files changed, 43 insertions, 30 deletions
diff --git a/activerecord/Rakefile b/activerecord/Rakefile index f7585f789b..2511f13fed 100644 --- a/activerecord/Rakefile +++ b/activerecord/Rakefile @@ -49,11 +49,13 @@ task :test do run_without_aborting(*tasks) end -task :isolated_test do - tasks = defined?(JRUBY_VERSION) ? - %w(isolated_test_jdbcmysql isolated_test_jdbcsqlite3 isolated_test_jdbcpostgresql) : - %w(isolated_test_mysql isolated_test_sqlite3 isolated_test_postgresql) - run_without_aborting(*tasks) +namespace :test do + task :isolated do + tasks = defined?(JRUBY_VERSION) ? + %w(isolated_test_jdbcmysql isolated_test_jdbcsqlite3 isolated_test_jdbcpostgresql) : + %w(isolated_test_mysql isolated_test_sqlite3 isolated_test_postgresql) + run_without_aborting(*tasks) + end end %w( mysql postgresql sqlite3 firebird db2 oracle sybase openbase frontbase jdbcmysql jdbcpostgresql jdbcsqlite3 jdbcderby jdbch2 jdbchsqldb ).each do |adapter| diff --git a/activerecord/activerecord.gemspec b/activerecord/activerecord.gemspec index 204cddde47..c84a3ac5a9 100644 --- a/activerecord/activerecord.gemspec +++ b/activerecord/activerecord.gemspec @@ -9,7 +9,7 @@ Gem::Specification.new do |s| s.add_dependency('activesupport', '= 3.0.pre') s.add_dependency('activemodel', '= 3.0.pre') - s.add_dependency('arel', '~> 0.1.1') + s.add_dependency('arel', '= 0.2.pre') s.require_path = 'lib' s.autorequire = 'active_record' diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 0888c41396..3a5f3ed030 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1480,7 +1480,7 @@ module ActiveRecord if reflection.options.include?(:dependent) # Add polymorphic type if the :as option is present dependent_conditions = [] - dependent_conditions << "#{reflection.primary_key_name} = \#{record.quoted_id}" + dependent_conditions << "#{reflection.primary_key_name} = \#{record.#{reflection.name}.send(:owner_quoted_id)}" dependent_conditions << "#{reflection.options[:as]}_type = '#{base_class.name}'" if reflection.options[:as] dependent_conditions << sanitize_sql(reflection.options[:conditions], reflection.quoted_table_name) if reflection.options[:conditions] dependent_conditions << extra_conditions if extra_conditions @@ -1724,7 +1724,7 @@ module ActiveRecord if (ids_array = select_limited_ids_array(options, join_dependency)).empty? throw :invalid_query else - Arel::In.new( + Arel::Predicates::In.new( Arel::SqlLiteral.new("#{connection.quote_table_name table_name}.#{primary_key}"), ids_array ) diff --git a/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb b/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb index 4672b0723e..c646fe488b 100644 --- a/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb +++ b/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb @@ -84,7 +84,7 @@ module ActiveRecord else relation = arel_table(@reflection.options[:join_table]) relation.conditions(relation[@reflection.primary_key_name].eq(@owner.id). - and(Arel::In.new(relation[@reflection.association_foreign_key], records.map(&:id))) + and(Arel::Predicates::In.new(relation[@reflection.association_foreign_key], records.map(&:id))) ).delete end end diff --git a/activerecord/lib/active_record/associations/has_many_association.rb b/activerecord/lib/active_record/associations/has_many_association.rb index 29ba84ee37..cd31b0e211 100644 --- a/activerecord/lib/active_record/associations/has_many_association.rb +++ b/activerecord/lib/active_record/associations/has_many_association.rb @@ -71,7 +71,7 @@ module ActiveRecord else relation = arel_table(@reflection.table_name) relation.conditions(relation[@reflection.primary_key_name].eq(@owner.id). - and(Arel::In.new(relation[@reflection.klass.primary_key], records.map(&:id))) + and(Arel::Predicates::In.new(relation[@reflection.klass.primary_key], records.map(&:id))) ).update(relation[@reflection.primary_key_name] => nil) @owner.class.update_counters(@owner.id, cached_counter_attribute_name => -records.size) if has_cached_counter? diff --git a/activerecord/lib/active_record/attribute_methods/dirty.rb b/activerecord/lib/active_record/attribute_methods/dirty.rb index 4df0f1af69..4a3ab9ea82 100644 --- a/activerecord/lib/active_record/attribute_methods/dirty.rb +++ b/activerecord/lib/active_record/attribute_methods/dirty.rb @@ -1,5 +1,3 @@ -require 'active_support/core_ext/object/tap' - module ActiveRecord module AttributeMethods module Dirty diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 4e6090458a..056f29f029 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -12,7 +12,6 @@ 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_ext/symbol' require 'active_support/core_ext/object/metaclass' module ActiveRecord #:nodoc: diff --git a/activerecord/lib/active_record/nested_attributes.rb b/activerecord/lib/active_record/nested_attributes.rb index edcf547e01..ca3110a374 100644 --- a/activerecord/lib/active_record/nested_attributes.rb +++ b/activerecord/lib/active_record/nested_attributes.rb @@ -250,6 +250,8 @@ module ActiveRecord assign_nested_attributes_for_#{type}_association(:#{association_name}, attributes) end }, __FILE__, __LINE__ + + add_autosave_association_callbacks(reflection) else raise ArgumentError, "No association found for name `#{association_name}'. Has it been defined yet?" end diff --git a/activerecord/lib/active_record/notifications.rb b/activerecord/lib/active_record/notifications.rb index a5ce7ac524..562a5b91f4 100644 --- a/activerecord/lib/active_record/notifications.rb +++ b/activerecord/lib/active_record/notifications.rb @@ -1,5 +1,5 @@ require 'active_support/notifications' -ActiveSupport::Notifications.subscribe("sql") do |event| - ActiveRecord::Base.connection.log_info(event.payload[:sql], event.payload[:name], event.duration) +ActiveSupport::Notifications.subscribe("sql") do |name, before, after, result, instrumenter_id, payload| + ActiveRecord::Base.connection.log_info(payload[:sql], name, after - before) end diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index 6bc56ecf15..5f0eec754f 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -110,19 +110,17 @@ module ActiveRecord end def respond_to?(method) - if @relation.respond_to?(method) || Array.instance_methods.include?(method.to_s) - true - else - super - end + @relation.respond_to?(method) || Array.method_defined?(method) || super end private def method_missing(method, *args, &block) if @relation.respond_to?(method) @relation.send(method, *args, &block) - elsif Array.instance_methods.include?(method.to_s) + elsif Array.method_defined?(method) to_a.send(method, *args, &block) + else + super end end end diff --git a/activerecord/lib/active_record/validations.rb b/activerecord/lib/active_record/validations.rb index 0365cb592f..e8a2a72735 100644 --- a/activerecord/lib/active_record/validations.rb +++ b/activerecord/lib/active_record/validations.rb @@ -1,5 +1,3 @@ -require 'active_support/core_ext/integer/even_odd' - 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. diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index b193f8d8ba..86d14c9c81 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -659,6 +659,18 @@ class HasManyAssociationsTest < ActiveRecord::TestCase assert_equal 1, Client.find_all_by_client_of(firm.id).size end + def test_delete_all_association_with_primary_key_deletes_correct_records + firm = Firm.find(:first) + # break the vanilla firm_id foreign key + assert_equal 2, firm.clients.count + firm.clients.first.update_attribute(:firm_id, nil) + assert_equal 1, firm.clients(true).count + assert_equal 1, firm.clients_using_primary_key_with_delete_all.count + old_record = firm.clients_using_primary_key_with_delete_all.first + firm = Firm.find(:first) + firm.destroy + assert Client.find_by_id(old_record.id).nil? + end def test_creation_respects_hash_condition ms_client = companies(:first_firm).clients_like_ms_with_hash_conditions.build diff --git a/activerecord/test/cases/helper.rb b/activerecord/test/cases/helper.rb index 871cfa6468..25613da912 100644 --- a/activerecord/test/cases/helper.rb +++ b/activerecord/test/cases/helper.rb @@ -3,9 +3,11 @@ begin require "#{root}/vendor/gems/environment" rescue LoadError $:.unshift("#{root}/activesupport/lib") - $:.unshift("#{root}/activerecord/lib") end +lib = File.expand_path("#{File.dirname(__FILE__)}/../../lib") +$:.unshift(lib) unless $:.include?('lib') || $:.include?(lib) + require 'config' require 'rubygems' diff --git a/activerecord/test/cases/pooled_connections_test.rb b/activerecord/test/cases/pooled_connections_test.rb index f9eea3d118..2529a33dab 100644 --- a/activerecord/test/cases/pooled_connections_test.rb +++ b/activerecord/test/cases/pooled_connections_test.rb @@ -105,7 +105,7 @@ class PooledConnectionsTest < ActiveRecord::TestCase Thread.new do ActiveRecord::Base.connection.rollback_db_transaction ActiveRecord::Base.connection_pool.release_connection - end.join rescue nil + end add_record('three') end diff --git a/activerecord/test/cases/reflection_test.rb b/activerecord/test/cases/reflection_test.rb index 99e248743a..acd214eb5a 100644 --- a/activerecord/test/cases/reflection_test.rb +++ b/activerecord/test/cases/reflection_test.rb @@ -176,8 +176,8 @@ class ReflectionTest < ActiveRecord::TestCase def test_reflection_of_all_associations # FIXME these assertions bust a lot - assert_equal 36, Firm.reflect_on_all_associations.size - assert_equal 26, Firm.reflect_on_all_associations(:has_many).size + assert_equal 37, Firm.reflect_on_all_associations.size + assert_equal 27, Firm.reflect_on_all_associations(:has_many).size assert_equal 10, Firm.reflect_on_all_associations(:has_one).size assert_equal 0, Firm.reflect_on_all_associations(:belongs_to).size end diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index 4833d04aff..1a2c8030fb 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -78,7 +78,7 @@ class RelationTest < ActiveRecord::TestCase relation = Topic.all ["map", "uniq", "sort", "insert", "delete", "update"].each do |method| - assert relation.respond_to?(method) + assert relation.respond_to?(method), "Topic.all should respond to #{method.inspect}" end end diff --git a/activerecord/test/models/company.rb b/activerecord/test/models/company.rb index 469f5399ae..7e93fda1eb 100644 --- a/activerecord/test/models/company.rb +++ b/activerecord/test/models/company.rb @@ -68,6 +68,8 @@ class Firm < Company has_many :readonly_clients, :class_name => 'Client', :readonly => true has_many :clients_using_primary_key, :class_name => 'Client', :primary_key => 'name', :foreign_key => 'firm_name' + has_many :clients_using_primary_key_with_delete_all, :class_name => 'Client', + :primary_key => 'name', :foreign_key => 'firm_name', :dependent => :delete_all has_many :clients_grouped_by_firm_id, :class_name => "Client", :group => "firm_id", :select => "firm_id" has_many :clients_grouped_by_name, :class_name => "Client", :group => "name", :select => "name" diff --git a/activerecord/test/models/pirate.rb b/activerecord/test/models/pirate.rb index 05c5b666ae..f2c05dd48f 100644 --- a/activerecord/test/models/pirate.rb +++ b/activerecord/test/models/pirate.rb @@ -18,7 +18,7 @@ class Pirate < ActiveRecord::Base has_many :treasure_estimates, :through => :treasures, :source => :price_estimates # These both have :autosave enabled because accepts_nested_attributes_for is used on them. - has_one :ship, :validate => true + has_one :ship has_one :non_validated_ship, :class_name => 'Ship' has_many :birds has_many :birds_with_method_callbacks, :class_name => "Bird", diff --git a/activerecord/test/models/ship.rb b/activerecord/test/models/ship.rb index d0df951622..06759d64b8 100644 --- a/activerecord/test/models/ship.rb +++ b/activerecord/test/models/ship.rb @@ -1,7 +1,7 @@ class Ship < ActiveRecord::Base self.record_timestamps = false - belongs_to :pirate, :validate => true + belongs_to :pirate has_many :parts, :class_name => 'ShipPart', :autosave => true accepts_nested_attributes_for :pirate, :allow_destroy => true, :reject_if => proc { |attributes| attributes.empty? } |