aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/method_scoping_test.rb
diff options
context:
space:
mode:
authorDmitry Polushkin <dmitry.polushkin@gmail.com>2011-12-31 01:10:42 +0000
committerDmitry Polushkin <dmitry.polushkin@gmail.com>2011-12-31 01:10:42 +0000
commit04bc40ff501b1bf81bec7ce3937cb06c896ffc69 (patch)
tree88a33663195900df8a7307aefa2c9aaa561c3973 /activerecord/test/cases/method_scoping_test.rb
parent84eece0a823e9c601ea99a8709f24605a19bcbfd (diff)
parented17983ec56dec689a0311c7f8fcbeba9874e5a4 (diff)
downloadrails-04bc40ff501b1bf81bec7ce3937cb06c896ffc69.tar.gz
rails-04bc40ff501b1bf81bec7ce3937cb06c896ffc69.tar.bz2
rails-04bc40ff501b1bf81bec7ce3937cb06c896ffc69.zip
Merge branch 'master' of git://github.com/rails/rails
Diffstat (limited to 'activerecord/test/cases/method_scoping_test.rb')
-rw-r--r--activerecord/test/cases/method_scoping_test.rb42
1 files changed, 33 insertions, 9 deletions
diff --git a/activerecord/test/cases/method_scoping_test.rb b/activerecord/test/cases/method_scoping_test.rb
index 0ab4f30363..0f0621f2e0 100644
--- a/activerecord/test/cases/method_scoping_test.rb
+++ b/activerecord/test/cases/method_scoping_test.rb
@@ -103,7 +103,7 @@ class MethodScopingTest < ActiveRecord::TestCase
def test_scoped_find_include
# with the include, will retrieve only developers for the given project
- scoped_developers = Developer.send(:with_scope, :find => { :include => :projects }) do
+ scoped_developers = Developer.send(:with_scope, :find => { :eager_load => :projects }) do
Developer.find(:all, :conditions => 'projects.id = 2')
end
assert scoped_developers.include?(developers(:david))
@@ -203,7 +203,7 @@ class MethodScopingTest < ActiveRecord::TestCase
def test_scoped_count_include
# with the include, will retrieve only developers for the given project
- Developer.send(:with_scope, :find => { :include => :projects }) do
+ Developer.send(:with_scope, :find => { :eager_load => :projects }) do
assert_equal 1, Developer.count(:conditions => 'projects.id = 2')
end
end
@@ -268,7 +268,7 @@ class MethodScopingTest < ActiveRecord::TestCase
end
class NestedScopingTest < ActiveRecord::TestCase
- fixtures :authors, :developers, :projects, :comments, :posts
+ fixtures :authors, :developers, :projects, :comments, :posts, :developers_projects
def test_merge_options
Developer.send(:with_scope, :find => { :conditions => 'salary = 80000' }) do
@@ -338,7 +338,7 @@ class NestedScopingTest < ActiveRecord::TestCase
end
def test_nested_scoped_find_include
- Developer.send(:with_scope, :find => { :include => :projects }) do
+ Developer.send(:with_scope, :find => { :eager_load => :projects }) do
Developer.send(:with_scope, :find => { :conditions => "projects.id = 2" }) do
assert_nothing_raised { Developer.find(1) }
assert_equal('David', Developer.find(:first).name)
@@ -350,23 +350,47 @@ class NestedScopingTest < ActiveRecord::TestCase
# :include's remain unique and don't "double up" when merging
Developer.send(:with_scope, :find => { :include => :projects, :conditions => "projects.id = 2" }) do
Developer.send(:with_scope, :find => { :include => :projects }) do
- assert_equal 1, Developer.scoped.includes_values.uniq.length
- assert_equal 'David', Developer.find(:first).name
+ assert_deprecated do
+ assert_equal 1, Developer.scoped.includes_values.uniq.length
+ assert_equal 'David', Developer.find(:first).name
+ end
end
end
# the nested scope doesn't remove the first :include
Developer.send(:with_scope, :find => { :include => :projects, :conditions => "projects.id = 2" }) do
Developer.send(:with_scope, :find => { :include => [] }) do
- assert_equal 1, Developer.scoped.includes_values.uniq.length
- assert_equal('David', Developer.find(:first).name)
+ assert_deprecated do
+ assert_equal 1, Developer.scoped.includes_values.uniq.length
+ assert_equal('David', Developer.find(:first).name)
+ end
end
end
# mixing array and symbol include's will merge correctly
Developer.send(:with_scope, :find => { :include => [:projects], :conditions => "projects.id = 2" }) do
Developer.send(:with_scope, :find => { :include => :projects }) do
- assert_equal 1, Developer.scoped.includes_values.uniq.length
+ assert_deprecated do
+ assert_equal 1, Developer.scoped.includes_values.uniq.length
+ assert_equal('David', Developer.find(:first).name)
+ end
+ end
+ end
+ end
+
+ def test_nested_scoped_find_merged_eager_load
+ # :include's remain unique and don't "double up" when merging
+ Developer.send(:with_scope, :find => { :eager_load => :projects, :conditions => "projects.id = 2" }) do
+ Developer.send(:with_scope, :find => { :eager_load => :projects }) do
+ assert_equal 1, Developer.scoped.eager_load_values.uniq.length
+ assert_equal 'David', Developer.find(:first).name
+ end
+ end
+
+ # mixing array and symbol include's will merge correctly
+ Developer.send(:with_scope, :find => { :eager_load => [:projects], :conditions => "projects.id = 2" }) do
+ Developer.send(:with_scope, :find => { :eager_load => :projects }) do
+ assert_equal 1, Developer.scoped.eager_load_values.uniq.length
assert_equal('David', Developer.find(:first).name)
end
end