1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Ensure all the finder methods respect scoping

This commit is contained in:
Pratik Naik 2009-12-26 19:15:05 +05:30
parent 9a9f97af28
commit c6258ee313
2 changed files with 7 additions and 2 deletions

View file

@ -651,7 +651,7 @@ module ActiveRecord #:nodoc:
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 file

@ -188,7 +188,7 @@ class RelationTest < ActiveRecord::TestCase
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 @@ class RelationTest < ActiveRecord::TestCase
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 }