|
| 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