Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

#first doesn't take an order in this test #2883

Merged
merged 1 commit into from

2 participants

@dmathieu
Collaborator

I'm deeply sorry, I failed when pushing #2877, test of #first shouldn't take any order.

This happens because #first just adds a LIMIT to the SQL query, therefore not changing the records' order.

When #last orders the records by id (unless there's already an order provided) and takes the first elements (which were the last ones).

Therefore in postgresql, #last must be ordered by id in this test. Otherwise, the database will return them in a different, unpredictable order.

cc @arunagw @spastorino

@jonleighton jonleighton merged commit 3c846c2 into rails:master
@jonleighton
Collaborator

Also cherry picked to 3-1-stable in 679a4eb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 6, 2011
  1. @dmathieu
This page is out of date. Refresh to see the latest.
Showing with 1 addition and 1 deletion.
  1. +1 −1  activerecord/test/cases/named_scope_test.rb
View
2  activerecord/test/cases/named_scope_test.rb
@@ -181,7 +181,7 @@ def test_first_and_last_should_support_find_options
end
def test_first_and_last_should_allow_integers_for_limit
- assert_equal Topic.base.first(2), Topic.base.order("id").to_a.first(2)
+ assert_equal Topic.base.first(2), Topic.base.to_a.first(2)
assert_equal Topic.base.last(2), Topic.base.order("id").to_a.last(2)
end
Something went wrong with that request. Please try again.