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