From b984657b8da9754e87027c83e04c263ad3a16b7d Mon Sep 17 00:00:00 2001 From: Jan Xie Date: Wed, 5 Jan 2011 14:28:04 +0800 Subject: [PATCH 1/2] test scope not changed in associated collection methods --- .../associations/has_many_associations_test.rb | 6 ++++++ activerecord/test/models/brand.rb | 15 +++++++++++++++ activerecord/test/schema/schema.rb | 5 +++++ 3 files changed, 26 insertions(+), 0 deletions(-) create mode 100644 activerecord/test/models/brand.rb diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index 1ce91d7..7e4a05e 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -15,6 +15,7 @@ require 'models/invoice' require 'models/line_item' require 'models/car' require 'models/bulb' +require 'models/brand' class HasManyAssociationsTestForCountWithFinderSql < ActiveRecord::TestCase class Invoice < ActiveRecord::Base @@ -1327,4 +1328,9 @@ class HasManyAssociationsTest < ActiveRecord::TestCase assert_equal reply.id, first.id assert_equal true, first.approved? end + + def test_associated_collection_class_scope_is_not_affected_in_collection_method + b = Brand.create! + b.children.create! + end end diff --git a/activerecord/test/models/brand.rb b/activerecord/test/models/brand.rb new file mode 100644 index 0000000..fbc3522 --- /dev/null +++ b/activerecord/test/models/brand.rb @@ -0,0 +1,15 @@ +class Brand < ActiveRecord::Base + belongs_to :parent, :class_name => 'Brand' + has_many :children, :class_name => 'Brand', :foreign_key => :parent_id + + before_validation :find_parent_and_do_something + + private + + def find_parent_and_do_something + if self.parent_id + Brand.find(parent_id) # and do sth. + end + end + +end diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb index 5f9bb7e..783625a 100644 --- a/activerecord/test/schema/schema.rb +++ b/activerecord/test/schema/schema.rb @@ -82,6 +82,11 @@ ActiveRecord::Schema.define do t.boolean :value end + create_table :brands, :force => true do |t| + t.string :name + t.integer :parent_id + end + create_table :bulbs, :force => true do |t| t.integer :car_id t.string :name -- 1.6.6 From d330efe7004abf0c2d2254123a65a45e58e9aecd Mon Sep 17 00:00:00 2001 From: hemant Date: Thu, 20 Jan 2011 03:00:15 +0530 Subject: [PATCH 2/2] associated collection class scope doesnt get affected in collection create [#6252 state:resolved] --- .../associations/association_collection.rb | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb index b75e02c..3c4d4ef 100644 --- a/activerecord/lib/active_record/associations/association_collection.rb +++ b/activerecord/lib/active_record/associations/association_collection.rb @@ -470,7 +470,7 @@ module ActiveRecord ensure_owner_is_persisted! transaction do - scoped.scoping { build_record(attrs, &block) } + build_record(attrs, &block) end end -- 1.6.6