Permalink
Browse files

Default scope :order should be overridden by named scopes.

[#2346 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information...
1 parent a5ed7ee commit 628b4ad679b1971427a20461e8c2332d492e4655 @shurikp shurikp committed with jeremy Mar 26, 2009
Showing with 5 additions and 5 deletions.
  1. +2 −2 activerecord/lib/active_record/named_scope.rb
  2. +3 −3 activerecord/test/cases/method_scoping_test.rb
@@ -114,7 +114,7 @@ class Scope
end
end
- delegate :scopes, :with_scope, :to => :proxy_scope
+ delegate :scopes, :with_scope, :scoped_methods, :to => :proxy_scope
def initialize(proxy_scope, options, &block)
options ||= {}
@@ -178,7 +178,7 @@ def method_missing(method, *args, &block)
else
with_scope({:find => proxy_options, :create => proxy_options[:conditions].is_a?(Hash) ? proxy_options[:conditions] : {}}, :reverse_merge) do
method = :new if method == :build
- if current_scoped_methods_when_defined
+ if current_scoped_methods_when_defined && !scoped_methods.include?(current_scoped_methods_when_defined)
with_scope current_scoped_methods_when_defined do
proxy_scope.send(method, *args, &block)
end
@@ -628,9 +628,9 @@ def test_nested_scope
assert_equal expected, received
end
- def test_named_scope
- expected = Developer.find(:all, :order => 'salary DESC, name DESC').collect { |dev| dev.salary }
- received = DeveloperOrderedBySalary.by_name.find(:all).collect { |dev| dev.salary }
+ 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 628b4ad

Please sign in to comment.