Bring #reorder back

Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
This commit is contained in:
Sebastian Martinez 2011-03-28 10:19:41 -03:00 committed by Santiago Pastorino
parent 0a28073acc
commit fb21511040
4 changed files with 13 additions and 3 deletions

@ -439,7 +439,7 @@ class Base
class << self # Class methods
delegate :find, :first, :last, :all, :destroy, :destroy_all, :exists?, :delete, :delete_all, :update, :update_all, :to => :scoped
delegate :find_each, :find_in_batches, :to => :scoped
delegate :select, :group, :order, :except, :limit, :offset, :joins, :where, :preload, :eager_load, :includes, :from, :lock, :readonly, :having, :create_with, :to => :scoped
delegate :select, :group, :order, :except, :reorder, :limit, :offset, :joins, :where, :preload, :eager_load, :includes, :from, :lock, :readonly, :having, :create_with, :to => :scoped
delegate :count, :average, :minimum, :maximum, :sum, :calculate, :to => :scoped
# Executes a custom SQL query against your database and returns all the results. The results will

@ -62,6 +62,10 @@ def order(*args)
relation
end
def reorder(*args)
except(:order).order(args)
end
def joins(*args)
return self if args.compact.blank?

@ -429,9 +429,9 @@ def test_scope_overwrites_default
assert_equal expected, received
end
def test_except_and_order_overrides_default_scope_order
def test_reorder_overrides_default_scope_order
expected = Developer.order('name DESC').collect { |dev| dev.name }
received = DeveloperOrderedBySalary.except(:order).order('name DESC').collect { |dev| dev.name }
received = DeveloperOrderedBySalary.reorder('name DESC').collect { |dev| dev.name }
assert_equal expected, received
end

@ -151,6 +151,12 @@ def test_finding_with_order_concatenated
assert_equal topics(:fourth).title, topics.first.title
end
def test_finding_with_reorder
topics = Topic.order('author_name').order('title').reorder('id').all
topics_titles = topics.map{ |t| t.title }
assert_equal ['The First Topic', 'The Second Topic of the day', 'The Third Topic of the day', 'The Fourth Topic of the day'], topics_titles
end
def test_finding_with_order_and_take
entrants = Entrant.order("id ASC").limit(2).to_a