[PATCH] (+tests) with_scope :order doesn't work with include

(I’ve had this patch lying around for a couple of weeks, waiting for
Trac to come back up. noradio’s already had a look at it on IRC.
What’s the best way to submit patches while Trac is down?)

with_scope doesn’t support :order in the presence of :include. For
example:

{{{

We’re testing the interaction between :order, :include, and

with_scope.
TEST_ORDER = ‘tickets.created_at DESC’
TEST_INCLUDE = [‘owner’]
def test_find(opts1, opts2)
Ticket.with_scope(:find => opts1) do
Ticket.find(:all, opts2).map {|t| t.id }
end
end

In these examples, :order is respected.

test_find({ :order => TEST_ORDER }, {})
test_find({}, { :include => TEST_INCLUDE, :order => TEST_ORDER })
test_find({ :include => TEST_INCLUDE }, { :order => TEST_ORDER })

In these examples, :order is ignored.

test_find({ :include => TEST_INCLUDE, :order => TEST_ORDER }, {})
test_find({ :order => TEST_ORDER }, { :include => TEST_INCLUDE })
}}}

There’s some code duplication between
construct_finder_sql_with_included_associations and the usual
construct_finder_sql, and changeset r4274 for ticket #3887 only
modified one copy of the duplicate code.