Skip to content

Commit 98a6cff

Browse files
author
Anna
committed
removed deprecated artiverecord syntax
1 parent 20a117a commit 98a6cff

File tree

8 files changed

+24
-24
lines changed

8 files changed

+24
-24
lines changed

lib/active_record/connection_adapters/sqlserver/core_ext/explain_subscriber.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def call(*args)
1313
IGNORED_PAYLOADS = %w(SCHEMA EXPLAIN CACHE)
1414
SQLSERVER_EXPLAINED_SQLS = /(select|update|delete|insert)/i
1515

16-
# Need to modify the regex for the TSQL generated by this adapter so we can explain the proper sql statements
16+
# TODO Need to modify the regex for the TSQL generated by this adapter so we can explain the proper sql statements
1717
def ignore_sqlserver_payload?(payload)
1818
payload[:exception] || IGNORED_PAYLOADS.include?(payload[:name]) || payload[:sql] !~ SQLSERVER_EXPLAINED_SQLS
1919
end

lib/active_record/connection_adapters/sqlserver/database_statements.rb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def exec_query(sql, name = 'SQL', binds = [], sqlserver_options = {})
2525
end
2626
end
2727

28+
# TODO do something with added params. Rails 4 added 2 parameters and we're not using them.
2829
def exec_insert(sql, name, binds, pk = nil, sequence_name = nil)
2930
exec_query sql, name, binds, :insert => true
3031
end
@@ -128,15 +129,19 @@ def use_database(database=nil)
128129
def user_options
129130
return {} if sqlserver_azure?
130131
select_rows("dbcc useroptions",'SCHEMA').inject(HashWithIndifferentAccess.new) do |values,row|
131-
set_option = row.values[0].gsub(/\s+/,'_') if row.instance_of? Hash
132-
set_option = row[0].gsub(/\s+/,'_') if row.instance_of? Array
133-
user_value = row.values[1] if row.instance_of? Hash
134-
user_value = row[1] if row.instance_of? Array
132+
if row.instance_of? Hash
133+
set_option = row.values[0].gsub(/\s+/,'_')
134+
user_value = row.values[1]
135+
elsif row.instance_of? Array
136+
set_option = row[0].gsub(/\s+/,'_')
137+
user_value = row[1]
138+
end
135139
values[set_option] = user_value
136140
values
137141
end
138142
end
139143

144+
# TODO Rails 4 now supports isolation levels
140145
def user_options_dateformat
141146
if sqlserver_azure?
142147
select_value 'SELECT [dateformat] FROM [sys].[syslanguages] WHERE [langid] = @@LANGID', 'SCHEMA'

lib/active_record/connection_adapters/sqlserver/schema_statements.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ def rename_table(table_name, new_name)
5050

5151
def remove_column(table_name, column_name, type = nil)
5252
raise ArgumentError.new("You must specify at least one column name. Example: remove_column(:people, :first_name)") if (column_name.is_a? Array)
53-
# TODO: this deprecation warning should be fixed or removed
54-
# ActiveSupport::Deprecation.warn 'Passing multiple arguments to remove_columns is deprecated, please use just one column name, like: `remove_columns(:posts, :column_name, :type)`', caller if column_name
5553
remove_check_constraints(table_name, column_name)
5654
remove_default_constraint(table_name, column_name)
5755
remove_indexes(table_name, column_name)
@@ -271,8 +269,6 @@ def get_table_name(sql)
271269
elsif sql =~ /FROM\s+([^\(\s]+)\s*/i
272270
$1
273271
else
274-
# TODO:
275-
puts sql
276272
nil
277273
end
278274
end

test/cases/method_scoping_test_sqlserver.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ class NestedScopingTest < ActiveRecord::TestCase
1212

1313
fixtures :developers
1414

15-
15+
# TODO update test for rails 4
1616
def test_coerced_test_merged_scoped_find
1717
poor_jamis = developers(:poor_jamis)
1818
Developer.send(:with_scope, :find => { :conditions => "salary < 100000" }) do
1919
Developer.send(:with_scope, :find => { :offset => 1, :order => 'id asc' }) do
2020
assert_sql /ORDER BY id asc/i do
21-
assert_equal(poor_jamis, Developer.first(:order => 'id asc'))
21+
assert_equal(poor_jamis, Developer.order('id asc').first)
2222
end
2323
end
2424
end

test/cases/offset_and_limit_test_sqlserver.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ class OffsetAndLimitTestSqlserver < ActiveRecord::TestCase
2121
context 'When selecting with limit' do
2222

2323
should 'alter sql to limit number of records returned' do
24-
assert_sql(/SELECT TOP \(10\)/) { Book.limit(10).all }
24+
assert_sql(/SELECT TOP \(10\)/) { Book.limit(10) }
2525
end
2626

2727
end
2828

2929
context 'When selecting with offset' do
3030

3131
should 'have limit (top) of 9223372036854775807 if only offset is passed' do
32-
assert_sql(/SELECT TOP \(9223372036854775807\) \[__rnt\]\.\* FROM.*WHERE \[__rnt\]\.\[__rn\] > \(1\)/) { Book.all(:offset=>1) }
32+
assert_sql(/SELECT TOP \(9223372036854775807\) \[__rnt\]\.\* FROM.*WHERE \[__rnt\]\.\[__rn\] > \(1\)/) { Book.offset(1) }
3333
end
3434

3535
should 'support calling exists?' do
@@ -47,12 +47,12 @@ class OffsetAndLimitTestSqlserver < ActiveRecord::TestCase
4747

4848
should 'alter SQL to limit number of records returned offset by specified amount' do
4949
sql = %|EXEC sp_executesql N'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) ORDER BY [__rnt].[__rn] ASC'|
50-
assert_sql(sql) { Book.limit(3).offset(5).all }
50+
assert_sql(sql) { Book.limit(3).offset(5) }
5151
end
5252

5353
should 'add locks to deepest sub select' do
5454
pattern = /FROM \[books\]\s+WITH \(NOLOCK\)/
55-
assert_sql(pattern) { Book.all :limit => 3, :offset => 5, :lock => 'WITH (NOLOCK)' }
55+
assert_sql(pattern) { Book.load :limit => 3, :offset => 5, :lock => 'WITH (NOLOCK)' }
5656
assert_sql(pattern) { Book.count :limit => 3, :offset => 5, :lock => 'WITH (NOLOCK)' }
5757
end
5858

test/cases/session_test_sqlserver.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
require 'cases/sqlserver_helper'
22
require 'action_dispatch'
3-
# TODO: require 'active_record/session_store'
4-
# Active Record's Session Store extracted from Rails
3+
54
module ActiveRecord
65
class SessionStore
76
class SessionTest < ActiveRecord::TestCase

test/cases/specific_schema_test_sqlserver.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class SpecificSchemaTestSqlserver < ActiveRecord::TestCase
7676

7777
should 'use primary key for row table order in pagination sql' do
7878
sql = /OVER \(ORDER BY \[natural_pk_data\]\.\[legacy_id\] ASC\)/
79-
assert_sql(sql) { SqlServerNaturalPkData.limit(5).offset(5).all }
79+
assert_sql(sql) { SqlServerNaturalPkData.limit(5).offset(5) }
8080
end
8181

8282
end
@@ -113,11 +113,11 @@ class SpecificSchemaTestSqlserver < ActiveRecord::TestCase
113113
teardown { @edge_class.delete_all }
114114

115115
should 'allow all sorts of ordering without adapter munging it up' do
116-
assert_equal ['A','B','C'], @edge_class.all(:order => 'description').map(&:description)
117-
assert_equal ['A','B','C'], @edge_class.all(:order => 'description asc').map(&:description)
118-
assert_equal ['A','B','C'], @edge_class.all(:order => 'description ASC').map(&:description)
119-
assert_equal ['C','B','A'], @edge_class.all(:order => 'description desc').map(&:description)
120-
assert_equal ['C','B','A'], @edge_class.all(:order => 'description DESC').map(&:description)
116+
assert_equal ['A','B','C'], @edge_class.load.order('description').map(&:description)
117+
assert_equal ['A','B','C'], @edge_class.load.order('description asc').map(&:description)
118+
assert_equal ['A','B','C'], @edge_class.load.order('description ASC').map(&:description)
119+
assert_equal ['C','B','A'], @edge_class.load.order('description desc').map(&:description)
120+
assert_equal ['C','B','A'], @edge_class.load.order('description DESC').map(&:description)
121121
end
122122

123123
end

test/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ default_connection_info: &default_connection_info
99
username: <%= ENV['ACTIVERECORD_UNITTEST_USER'] || 'rails' %>
1010
password: <%= ENV['ACTIVERECORD_UNITTEST_PASS'] || '' %>
1111
azure: <%= !ENV['ACTIVERECORD_UNITTEST_AZURE'].nil? %>
12-
timeout: 0
12+
1313
connections:
1414

1515
dblib:

0 commit comments

Comments
 (0)