From 1dff403b2d10099b5b1e15ade9cf2b8f032b62c7 Mon Sep 17 00:00:00 2001 From: Jan Xie Date: Wed, 5 Jan 2011 14:28:04 +0800 Subject: [PATCH] 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 2b7ad36..f3789d1 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 @@ -1314,4 +1315,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 7f366b2..8ebef81 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.7.3.4