From f7bd0beb67c5d9d50e37aa596605b91e61197fbe Mon Sep 17 00:00:00 2001 From: Daniel Luz Date: Sun, 21 Dec 2008 22:38:12 +0000 Subject: Ensure Model#last doesn't affects order for another finders inside the same scope [#1499 state:resolved] Signed-off-by: Pratik Naik --- activerecord/test/cases/method_scoping_test.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'activerecord/test') 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'") -- cgit v1.2.3