mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Ensure all the finder methods respect scoping
This commit is contained in:
@@ -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>.
|
||||
|
||||
@@ -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 }
|
||||
|
||||
Reference in New Issue
Block a user