1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Default scope :order should be overridden by named scopes.

[#2346 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
This commit is contained in:
Alexander Podgorbunsky 2009-03-26 15:00:12 +03:00 committed by Jeremy Kemper
parent 853c229bbd
commit db0bfe4ede
2 changed files with 5 additions and 5 deletions

View file

@ -114,7 +114,7 @@ module ActiveRecord
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 @@ module ActiveRecord
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

View file

@ -628,9 +628,9 @@ class DefaultScopingTest < ActiveRecord::TestCase
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