Skip to content

Commit 5550f6f

Browse files
committed
We are deterministic if you are explicit about your tie breakers.
1 parent 51aab54 commit 5550f6f

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

‎test/cases/coerced_tests.rb

+19
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,25 @@ def test_add_table_with_decimals_coerced
412412

413413

414414

415+
class NamedScopingTest < ActiveRecord::TestCase
416+
417+
# This works now because we add an `order(:id)` sort to break the order tie for deterministic results.
418+
coerce_tests! :test_scopes_honor_current_scopes_from_when_defined
419+
def test_scopes_honor_current_scopes_from_when_defined_coerced
420+
assert !Post.ranked_by_comments.order(:id).limit_by(5).empty?
421+
assert !authors(:david).posts.ranked_by_comments.order(:id).limit_by(5).empty?
422+
assert_not_equal Post.ranked_by_comments.order(:id).limit_by(5), authors(:david).posts.ranked_by_comments.order(:id).limit_by(5)
423+
assert_not_equal Post.order(:id).top(5), authors(:david).posts.order(:id).top(5)
424+
# Oracle sometimes sorts differently if WHERE condition is changed
425+
assert_equal authors(:david).posts.ranked_by_comments.limit_by(5).to_a.sort_by(&:id), authors(:david).posts.top(5).to_a.sort_by(&:id)
426+
assert_equal Post.ranked_by_comments.limit_by(5), Post.top(5)
427+
end
428+
429+
end
430+
431+
432+
433+
415434
require 'models/developer'
416435
require 'models/computer'
417436
class NestedRelationScopingTest < ActiveRecord::TestCase

‎test/cases/fetch_test_sqlserver.rb

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
require 'cases/helper_sqlserver'
2+
require 'models/book'
3+
4+
class FetchTestSqlserver < ActiveRecord::TestCase
5+
6+
let(:books) { @books }
7+
8+
before { create_10_books }
9+
10+
it 'work with fully qualified table and columns in select' do
11+
books = Book.select('books.id, books.name').limit(3).offset(5)
12+
assert_equal Book.all[5,3].map(&:id), books.map(&:id)
13+
end
14+
15+
describe 'count' do
16+
17+
it 'gauntlet' do
18+
books[0].destroy
19+
books[1].destroy
20+
books[2].destroy
21+
assert_equal 7, Book.count
22+
assert_equal 1, Book.limit(1).offset(1).count
23+
assert_equal 1, Book.limit(1).offset(5).count
24+
assert_equal 1, Book.limit(1).offset(6).count
25+
assert_equal 0, Book.limit(1).offset(7).count
26+
assert_equal 3, Book.limit(3).offset(4).count
27+
assert_equal 2, Book.limit(3).offset(5).count
28+
assert_equal 1, Book.limit(3).offset(6).count
29+
assert_equal 0, Book.limit(3).offset(7).count
30+
assert_equal 0, Book.limit(3).offset(8).count
31+
end
32+
33+
end
34+
35+
describe 'order' do
36+
37+
it 'gauntlet' do
38+
Book.where(name:'Name-10').delete_all
39+
Book.order(:name).limit(1).offset(1).map(&:name).must_equal ['Name-2']
40+
Book.order(:name).limit(2).offset(2).map(&:name).must_equal ['Name-3', 'Name-4']
41+
Book.order(:name).limit(2).offset(7).map(&:name).must_equal ['Name-8', 'Name-9']
42+
Book.order(:name).limit(3).offset(7).map(&:name).must_equal ['Name-8', 'Name-9']
43+
Book.order(:name).limit(3).offset(9).map(&:name).must_equal []
44+
end
45+
46+
end
47+
48+
49+
protected
50+
51+
def create_10_books
52+
Book.delete_all
53+
@books = (1..10).map { |i| Book.create! name: "Name-#{i}" }
54+
end
55+
56+
end
57+

0 commit comments

Comments
 (0)