aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/method_scoping_test.rb
diff options
context:
space:
mode:
authorDaniel Luz <dev@mernen.com>2008-12-21 22:38:12 +0000
committerPratik Naik <pratiknaik@gmail.com>2008-12-21 23:24:06 +0000
commitf7bd0beb67c5d9d50e37aa596605b91e61197fbe (patch)
tree19cadf3a53bc48920c7f3fc6e5dd9c8f7e10f4fc /activerecord/test/cases/method_scoping_test.rb
parent389534c38c3baaa63ce5cc2ba3bd169415419167 (diff)
downloadrails-f7bd0beb67c5d9d50e37aa596605b91e61197fbe.tar.gz
rails-f7bd0beb67c5d9d50e37aa596605b91e61197fbe.tar.bz2
rails-f7bd0beb67c5d9d50e37aa596605b91e61197fbe.zip
Ensure Model#last doesn't affects order for another finders inside the same scope [#1499 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'activerecord/test/cases/method_scoping_test.rb')
-rw-r--r--activerecord/test/cases/method_scoping_test.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/activerecord/test/cases/method_scoping_test.rb b/activerecord/test/cases/method_scoping_test.rb
index 6372b4f6aa..80a06116ad 100644
--- a/activerecord/test/cases/method_scoping_test.rb
+++ b/activerecord/test/cases/method_scoping_test.rb
@@ -27,6 +27,24 @@ class MethodScopingTest < ActiveRecord::TestCase
end
end
+ def test_scoped_find_last
+ highest_salary = Developer.find(:first, :order => "salary DESC")
+
+ Developer.with_scope(:find => { :order => "salary" }) do
+ assert_equal highest_salary, Developer.last
+ end
+ end
+
+ def test_scoped_find_last_preserves_scope
+ lowest_salary = Developer.find(:first, :order => "salary ASC")
+ highest_salary = Developer.find(:first, :order => "salary DESC")
+
+ Developer.with_scope(:find => { :order => "salary" }) do
+ assert_equal highest_salary, Developer.last
+ assert_equal lowest_salary, Developer.first
+ end
+ end
+
def test_scoped_find_combines_conditions
Developer.with_scope(:find => { :conditions => "salary = 9000" }) do
assert_equal developers(:poor_jamis), Developer.find(:first, :conditions => "name = 'Jamis'")