Skip to content

Commit 995f008

Browse files
committed
Fix limit/offset tests.
1 parent 36f860e commit 995f008

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

test/cases/offset_and_limit_test_sqlserver.rb

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,12 @@ class OffsetAndLimitTestSqlserver < ActiveRecord::TestCase
4141
end
4242

4343
should 'alter SQL to limit number of records returned offset by specified amount' do
44-
sql = %|SELECT TOP (3) [__rnt].*
45-
FROM (
46-
SELECT ROW_NUMBER() OVER (ORDER BY [books].[id]) AS [__rn], [books].*
47-
FROM [books]
48-
) AS [__rnt]
49-
WHERE [__rnt].[__rn] > 5|.squish
44+
sql = %|SELECT TOP (3) [__rnt].* FROM ( SELECT ROW_NUMBER() OVER (ORDER BY [books].[id] ASC) AS [__rn], [books].* FROM [books] ) AS [__rnt] WHERE [__rnt].[__rn] > 5|
5045
assert_sql(sql) { Book.limit(3).offset(5).all }
5146
end
5247

5348
should 'add locks to deepest sub select' do
54-
pattern = /FROM \[books\] WITH \(NOLOCK\)/
49+
pattern = /FROM \[books\]\s+WITH \(NOLOCK\)/
5550
assert_sql(pattern) { Book.all :limit => 3, :offset => 5, :lock => 'WITH (NOLOCK)' }
5651
assert_sql(pattern) { Book.count :limit => 3, :offset => 5, :lock => 'WITH (NOLOCK)' }
5752
end

test/cases/scratch_test_sqlserver.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ class ScratchTestSqlserver < ActiveRecord::TestCase
1111

1212

1313
should 'pass' do
14-
raise Book.all(:offset=>1).inspect
14+
Book.all :limit => 3, :offset => 5, :lock => 'WITH (NOLOCK)'
15+
Book.count :limit => 3, :offset => 5, :lock => 'WITH (NOLOCK)'
16+
# pattern = /FROM \[books\] WITH \(NOLOCK\)/
17+
# assert_sql(pattern) { Book.all :limit => 3, :offset => 5, :lock => 'WITH (NOLOCK)' }
18+
# assert_sql(pattern) { Book.count :limit => 3, :offset => 5, :lock => 'WITH (NOLOCK)' }
1519
end
1620

1721

test/cases/sqlserver_helper.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ def method_added(method)
8282
ActiveRecord::Base.connection.class.class_eval do
8383
IGNORED_SQL << %r|SELECT SCOPE_IDENTITY| << %r{INFORMATION_SCHEMA\.(TABLES|VIEWS|COLUMNS)} <<
8484
%r|SELECT @@IDENTITY| << %r|SELECT @@ROWCOUNT| << %r|SELECT @@version| << %r|SELECT @@TRANCOUNT|
85-
def select_with_query_record(sql, name=nil)
85+
def raw_select_with_query_record(sql, name=nil, options={})
8686
$queries_executed ||= []
8787
$queries_executed << sql unless IGNORED_SQL.any? { |r| sql =~ r }
88-
select_without_query_record(sql, name)
88+
raw_select_without_query_record(sql, name, options)
8989
end
90-
alias_method_chain :select, :query_record
90+
alias_method_chain :raw_select, :query_record
9191
end
9292

9393
module ActiveRecord

0 commit comments

Comments
 (0)