aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2009-12-26 19:15:05 +0530
committerPratik Naik <pratiknaik@gmail.com>2009-12-26 19:15:05 +0530
commitc6258ee313653bc54e94e0008f1c098ed68aa3f4 (patch)
tree98cb7b207f385790183ddd953f0183b667e13765 /activerecord
parent9a9f97af2815469e6f28dee9b88577251ef1b832 (diff)
downloadrails-c6258ee313653bc54e94e0008f1c098ed68aa3f4.tar.gz
rails-c6258ee313653bc54e94e0008f1c098ed68aa3f4.tar.bz2
rails-c6258ee313653bc54e94e0008f1c098ed68aa3f4.zip
Ensure all the finder methods respect scoping
Diffstat (limited to 'activerecord')
-rwxr-xr-xactiverecord/lib/active_record/base.rb2
-rw-r--r--activerecord/test/cases/relations_test.rb7
2 files changed, 7 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 3c41d16f63..b6d73265a8 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -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>.
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index 2b3c6eec1d..e05da58ae6 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -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 }