aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/method_scoping_test.rb
diff options
context:
space:
mode:
authorTom Stuart <tom@experthuman.com>2008-11-17 20:10:59 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2008-11-17 22:00:14 +0100
commit32cb2345a54b9ab38461b2d4bb0dbd1706f2800e (patch)
tree9da1d7efd04f2f589c777699e2d3c6274820d4be /activerecord/test/cases/method_scoping_test.rb
parent3a33ee28e9babc5a1a78079f5ca50ea6249f2643 (diff)
downloadrails-32cb2345a54b9ab38461b2d4bb0dbd1706f2800e.tar.gz
rails-32cb2345a54b9ab38461b2d4bb0dbd1706f2800e.tar.bz2
rails-32cb2345a54b9ab38461b2d4bb0dbd1706f2800e.zip
Fix default_scope to work in combination with named scopes
Signed-off-by: David Heinemeier Hansson <david@loudthinking.com>
Diffstat (limited to 'activerecord/test/cases/method_scoping_test.rb')
-rw-r--r--activerecord/test/cases/method_scoping_test.rb12
1 files changed, 9 insertions, 3 deletions
diff --git a/activerecord/test/cases/method_scoping_test.rb b/activerecord/test/cases/method_scoping_test.rb
index 4ac0018144..6372b4f6aa 100644
--- a/activerecord/test/cases/method_scoping_test.rb
+++ b/activerecord/test/cases/method_scoping_test.rb
@@ -532,7 +532,7 @@ class DefaultScopingTest < ActiveRecord::TestCase
end
def test_default_scoping_with_threads
- scope = [{:create=>nil, :find=>{:order=>"salary DESC"}}]
+ scope = [{ :create => {}, :find => { :order => 'salary DESC' } }]
2.times do
Thread.new { assert_equal scope, DeveloperOrderedBySalary.send(:scoped_methods) }.join
@@ -540,14 +540,14 @@ class DefaultScopingTest < ActiveRecord::TestCase
end
def test_default_scoping_with_inheritance
- scope = [{:create=>nil, :find=>{:order=>"salary DESC"}}]
+ scope = [{ :create => {}, :find => { :order => 'salary DESC' } }]
# Inherit a class having a default scope and define a new default scope
klass = Class.new(DeveloperOrderedBySalary)
klass.send :default_scope, {}
# Scopes added on children should append to parent scope
- expected_klass_scope = [{:create=>nil, :find=>{:order=>"salary DESC"}}, {:create=>nil, :find=>{}}]
+ expected_klass_scope = [{ :create => {}, :find => { :order => 'salary DESC' }}, { :create => {}, :find => {} }]
assert_equal expected_klass_scope, klass.send(:scoped_methods)
# Parent should still have the original scope
@@ -568,6 +568,12 @@ class DefaultScopingTest < ActiveRecord::TestCase
assert_equal expected, received
end
+ def test_named_scope
+ expected = Developer.find(:all, :order => 'name DESC').collect { |dev| dev.salary }
+ received = DeveloperOrderedBySalary.by_name.find(:all).collect { |dev| dev.salary }
+ assert_equal expected, received
+ end
+
def test_nested_exclusive_scope
expected = Developer.find(:all, :limit => 100).collect { |dev| dev.salary }
received = DeveloperOrderedBySalary.with_exclusive_scope(:find => { :limit => 100 }) do