Browse files

Ensure all the finder methods respect scoping

  • Loading branch information...
1 parent 9a9f97a commit c6258ee313653bc54e94e0008f1c098ed68aa3f4 @lifo lifo committed Dec 26, 2009
Showing with 7 additions and 2 deletions.
  1. +1 −1 activerecord/lib/active_record/base.rb
  2. +6 −1 activerecord/test/cases/relations_test.rb
View
2 activerecord/lib/active_record/base.rb
@@ -651,7 +651,7 @@ def find(*args)
end
end
- delegate :select, :group, :order, :limit, :joins, :where, :preload, :eager_load, :to => :arel_table
+ delegate :select, :group, :order, :limit, :joins, :where, :preload, :eager_load, :to => :scoped
# A convenience wrapper for <tt>find(:first, *args)</tt>. You can pass in all the
# same arguments to this method as you can to <tt>find(:first)</tt>.
View
7 activerecord/test/cases/relations_test.rb
@@ -188,7 +188,7 @@ def test_find_with_included_associations
end
def test_default_scope_with_conditions_string
- assert_equal Developer.find_all_by_name('David').map(&:id).sort, DeveloperCalledDavid.scoped.to_a.map(&:id).sort
+ assert_equal Developer.find_all_by_name('David').map(&:id).sort, DeveloperCalledDavid.scoped.map(&:id).sort
assert_equal nil, DeveloperCalledDavid.create!.name
end
@@ -197,6 +197,11 @@ def test_default_scope_with_conditions_hash
assert_equal 'Jamis', DeveloperCalledJamis.create!.name
end
+ def test_default_scoping_finder_methods
+ developers = DeveloperCalledDavid.order('id').map(&:id).sort
+ assert_equal Developer.find_all_by_name('David').map(&:id).sort, developers
+ end
+
def test_loading_with_one_association
posts = Post.preload(:comments)
post = posts.find { |p| p.id == 1 }

0 comments on commit c6258ee

Please sign in to comment.