Permalink
Browse files

Make merging of order values consistent

  • Loading branch information...
1 parent f9a4300 commit 54a043895f904e0237a590738d494554ec555265 @lifo lifo committed Jan 17, 2010
View
2 activerecord/lib/active_record/relation/spawn_methods.rb
@@ -33,7 +33,7 @@ def merge(r)
from(r.from_value).
having(r.having_values)
- merged_relation.order_values = Array.wrap(order_values) + Array.wrap(r.order_values)
+ merged_relation.order_values = r.order_values if r.order_values.present?
merged_relation.create_with_value = @create_with_value
View
4 activerecord/test/cases/base_test.rb
@@ -1865,7 +1865,9 @@ def test_scoped_find_order
end
assert scoped_developers.include?(developers(:poor_jamis))
assert scoped_developers.include?(developers(:david))
- assert scoped_developers.include?(developers(:dev_10))
+ assert ! scoped_developers.include?(developers(:jamis))
+ assert_equal 3, scoped_developers.size
+
# Test without scoped find conditions to ensure we get the right thing
developers = Developer.find(:all, :order => 'id', :limit => 1)
assert scoped_developers.include?(developers(:david))
View
8 activerecord/test/cases/method_scoping_test.rb
@@ -625,21 +625,21 @@ def test_default_scoping_with_inheritance
end
def test_method_scope
- expected = Developer.find(:all, :order => 'name DESC, salary DESC').collect { |dev| dev.salary }
+ expected = Developer.find(:all, :order => 'name DESC').collect { |dev| dev.salary }
received = DeveloperOrderedBySalary.all_ordered_by_name.collect { |dev| dev.salary }
assert_equal expected, received
end
def test_nested_scope
- expected = Developer.find(:all, :order => 'name DESC, salary DESC').collect { |dev| dev.salary }
+ expected = Developer.find(:all, :order => 'name DESC').collect { |dev| dev.salary }
received = DeveloperOrderedBySalary.send(:with_scope, :find => { :order => 'name DESC'}) do
DeveloperOrderedBySalary.find(:all).collect { |dev| dev.salary }
end
assert_equal expected, received
end
- def test_named_scope_order_appended_to_default_scope_order
- expected = Developer.find(:all, :order => 'name DESC, salary DESC').collect { |dev| dev.name }
+ def test_named_scope_overwrites_default
+ expected = Developer.find(:all, :order => 'name DESC').collect { |dev| dev.name }
received = DeveloperOrderedBySalary.by_name.find(:all).collect { |dev| dev.name }
assert_equal expected, received
end

0 comments on commit 54a0438

Please sign in to comment.