aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2010-06-04 00:53:45 +0100
committerPratik Naik <pratiknaik@gmail.com>2010-06-04 00:53:45 +0100
commit517f709b51d1d2766d1a783d9f02fa7a6a41abc4 (patch)
tree8b7e8f0ee8faca37f6a03eae6ccfa85a89e13d1b /activerecord/test
parent3a066e81b34fbad93edce1776354f879f30ce4e8 (diff)
downloadrails-517f709b51d1d2766d1a783d9f02fa7a6a41abc4.tar.gz
rails-517f709b51d1d2766d1a783d9f02fa7a6a41abc4.tar.bz2
rails-517f709b51d1d2766d1a783d9f02fa7a6a41abc4.zip
Properly cache association_collection#scopes calls having arguments
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/named_scope_test.rb13
-rw-r--r--activerecord/test/models/comment.rb1
2 files changed, 14 insertions, 0 deletions
diff --git a/activerecord/test/cases/named_scope_test.rb b/activerecord/test/cases/named_scope_test.rb
index 2007f5492f..91d8d2828b 100644
--- a/activerecord/test/cases/named_scope_test.rb
+++ b/activerecord/test/cases/named_scope_test.rb
@@ -428,6 +428,19 @@ class NamedScopeTest < ActiveRecord::TestCase
assert_no_queries { post.comments.containing_the_letter_e.all }
end
+ def test_named_scopes_with_arguments_are_cached_on_associations
+ post = posts(:welcome)
+
+ one = post.comments.limit_by(1).all
+ assert_equal 1, one.size
+
+ two = post.comments.limit_by(2).all
+ assert_equal 2, two.size
+
+ assert_no_queries { post.comments.limit_by(1).all }
+ assert_no_queries { post.comments.limit_by(2).all }
+ end
+
def test_named_scopes_are_reset_on_association_reload
post = posts(:welcome)
diff --git a/activerecord/test/models/comment.rb b/activerecord/test/models/comment.rb
index a8a99f6dce..9f6e2d3b71 100644
--- a/activerecord/test/models/comment.rb
+++ b/activerecord/test/models/comment.rb
@@ -1,4 +1,5 @@
class Comment < ActiveRecord::Base
+ scope :limit_by, lambda {|l| limit(l) }
scope :containing_the_letter_e, :conditions => "comments.body LIKE '%e%'"
scope :for_first_post, :conditions => { :post_id => 1 }
scope :for_first_author,