Permalink
Browse files

Fix limit/offset tests.

  • Loading branch information...
1 parent 36f860e commit 995f008ff05aa3be7401da7a11b6e0b7d0ec9a93 @metaskills metaskills committed Jan 13, 2011
@@ -41,17 +41,12 @@ class OffsetAndLimitTestSqlserver < ActiveRecord::TestCase
end
should 'alter SQL to limit number of records returned offset by specified amount' do
- sql = %|SELECT TOP (3) [__rnt].*
- FROM (
- SELECT ROW_NUMBER() OVER (ORDER BY [books].[id]) AS [__rn], [books].*
- FROM [books]
- ) AS [__rnt]
- WHERE [__rnt].[__rn] > 5|.squish
+ 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|
assert_sql(sql) { Book.limit(3).offset(5).all }
end
should 'add locks to deepest sub select' do
- pattern = /FROM \[books\] WITH \(NOLOCK\)/
+ pattern = /FROM \[books\]\s+WITH \(NOLOCK\)/
assert_sql(pattern) { Book.all :limit => 3, :offset => 5, :lock => 'WITH (NOLOCK)' }
assert_sql(pattern) { Book.count :limit => 3, :offset => 5, :lock => 'WITH (NOLOCK)' }
end
@@ -11,7 +11,11 @@ class ScratchTestSqlserver < ActiveRecord::TestCase
should 'pass' do
- raise Book.all(:offset=>1).inspect
+ Book.all :limit => 3, :offset => 5, :lock => 'WITH (NOLOCK)'
+ Book.count :limit => 3, :offset => 5, :lock => 'WITH (NOLOCK)'
+ # pattern = /FROM \[books\] WITH \(NOLOCK\)/
+ # assert_sql(pattern) { Book.all :limit => 3, :offset => 5, :lock => 'WITH (NOLOCK)' }
+ # assert_sql(pattern) { Book.count :limit => 3, :offset => 5, :lock => 'WITH (NOLOCK)' }
end
@@ -82,12 +82,12 @@ def method_added(method)
ActiveRecord::Base.connection.class.class_eval do
IGNORED_SQL << %r|SELECT SCOPE_IDENTITY| << %r{INFORMATION_SCHEMA\.(TABLES|VIEWS|COLUMNS)} <<
%r|SELECT @@IDENTITY| << %r|SELECT @@ROWCOUNT| << %r|SELECT @@version| << %r|SELECT @@TRANCOUNT|
- def select_with_query_record(sql, name=nil)
+ def raw_select_with_query_record(sql, name=nil, options={})
$queries_executed ||= []
$queries_executed << sql unless IGNORED_SQL.any? { |r| sql =~ r }
- select_without_query_record(sql, name)
+ raw_select_without_query_record(sql, name, options)
end
- alias_method_chain :select, :query_record
+ alias_method_chain :raw_select, :query_record
end
module ActiveRecord

0 comments on commit 995f008

Please sign in to comment.