aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenedikt Deicke <benedikt@synatic.net>2012-04-03 21:13:24 +0200
committerBenedikt Deicke <benedikt@synatic.net>2012-04-03 21:13:24 +0200
commit402576b044ce1cb06c3e48061f62542d0908fa17 (patch)
treebddb57fc6c9619df94bc2479d02c7f25658d380d
parent68677ffb8298105eb9d3efa26d928dd88cc5e006 (diff)
downloadrails-402576b044ce1cb06c3e48061f62542d0908fa17.tar.gz
rails-402576b044ce1cb06c3e48061f62542d0908fa17.tar.bz2
rails-402576b044ce1cb06c3e48061f62542d0908fa17.zip
Adds test to check that circular preloading does not modify Model.unscoped (as described in #5667)
-rw-r--r--activerecord/test/cases/associations/eager_test.rb6
-rw-r--r--activerecord/test/cases/relations_test.rb4
-rw-r--r--activerecord/test/models/comment.rb2
3 files changed, 8 insertions, 4 deletions
diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb
index efdb7cbb36..f7f44208b3 100644
--- a/activerecord/test/cases/associations/eager_test.rb
+++ b/activerecord/test/cases/associations/eager_test.rb
@@ -1174,6 +1174,12 @@ class EagerAssociationTest < ActiveRecord::TestCase
assert_equal Comment.find(1), Comment.preload(:post => :comments).scoping { Comment.find(1) }
end
+ test "circular preload does not modify unscoped" do
+ expected = FirstPost.unscoped.find(2)
+ FirstPost.preload(:comments => :first_post).find(1)
+ assert_equal expected, FirstPost.unscoped.find(2)
+ end
+
test "preload ignores the scoping" do
assert_equal(
Comment.find(1).post,
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index af25db05cf..25eb7c1672 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -1099,10 +1099,6 @@ class RelationTest < ActiveRecord::TestCase
assert_equal 'honda', FastCar.unscoped { FastCar.order_using_old_style.limit(1).first.name}
end
- def test_unscoped_relation_clones
- assert_not_equal CoolCar.unscoped.object_id, CoolCar.unscoped.object_id
- end
-
def test_intersection_with_array
relation = Author.where(:name => "David")
rails_author = relation.first
diff --git a/activerecord/test/models/comment.rb b/activerecord/test/models/comment.rb
index 00f5a74070..cf73c28ded 100644
--- a/activerecord/test/models/comment.rb
+++ b/activerecord/test/models/comment.rb
@@ -9,6 +9,8 @@ class Comment < ActiveRecord::Base
belongs_to :post, :counter_cache => true
has_many :ratings
+ belongs_to :first_post, :foreign_key => :post_id
+
has_many :children, :class_name => 'Comment', :foreign_key => :parent_id
belongs_to :parent, :class_name => 'Comment', :counter_cache => :children_count