Skip to content

Commit 4d0de64

Browse files
authored
Rails 6.1: remove deprecation warnings (#884)
* DEPRECATION WARNING: allowed_index_name_length is deprecated and will be removed from Rails 6.2 Deprecation commit rails/rails@ab2d859 * DEPRECATION WARNING: [] is deprecated and will be removed from Rails 6.2 (Use configs_for) Deprecation commit rails/rails@2a53fe6 * DEPRECATION WARNING: Passing an Active Record object to directly is deprecated and will be no longer quoted as id value in Rails 6.2 Deprecation commit rails/rails@87886c9 * DEPRECATION WARNING: with / no longer takes non-deterministic result in Rails 6.2. To continue taking non-deterministic result, use / instead. Deprecation commit rails/rails@eec562d
1 parent d67c2f6 commit 4d0de64

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

lib/active_record/connection_adapters/sqlserver/schema_statements.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def rename_column(table_name, column_name, new_column_name)
190190
end
191191

192192
def rename_index(table_name, old_name, new_name)
193-
raise ArgumentError, "Index name '#{new_name}' on table '#{table_name}' is too long; the limit is #{allowed_index_name_length} characters" if new_name.length > allowed_index_name_length
193+
raise ArgumentError, "Index name '#{new_name}' on table '#{table_name}' is too long; the limit is #{index_name_length} characters" if new_name.length > index_name_length
194194

195195
identifier = SQLServer::Utils.extract_identifiers("#{table_name}.#{old_name}")
196196
execute_procedure :sp_rename, identifier.quoted, new_name, "INDEX"

test/cases/adapter_test_sqlserver.rb

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ class AdapterTestSQLServer < ActiveRecord::TestCase
5353
assert Topic.table_exists?, "Topics table name of 'dbo.topics' should return true for exists."
5454

5555
# Test when database and owner included in table name.
56-
Topic.table_name = "#{ActiveRecord::Base.configurations["arunit"]['database']}.dbo.topics"
56+
db_config = ActiveRecord::Base.configurations.configs_for(env_name: "arunit", name: "primary")
57+
Topic.table_name = "#{db_config.database}.dbo.topics"
5758
assert Topic.table_exists?, "Topics table name of '[DATABASE].dbo.topics' should return true for exists."
5859
ensure
5960
Topic.table_name = "topics"
@@ -100,21 +101,23 @@ class AdapterTestSQLServer < ActiveRecord::TestCase
100101

101102
it "test bad connection" do
102103
assert_raise ActiveRecord::NoDatabaseError do
103-
config = ActiveRecord::Base.configurations["arunit"].merge(database: "inexistent_activerecord_unittest")
104-
ActiveRecord::Base.sqlserver_connection config
104+
db_config = ActiveRecord::Base.configurations.configs_for(env_name: "arunit", name: "primary")
105+
configuration = db_config.configuration_hash.merge(database: "inexistent_activerecord_unittest")
106+
ActiveRecord::Base.sqlserver_connection configuration
105107
end
106108
end
107109

108110
it "test database exists returns false if database does not exist" do
109-
config = ActiveRecord::Base.configurations["arunit"].merge(database: "inexistent_activerecord_unittest")
110-
assert_not ActiveRecord::ConnectionAdapters::SQLServerAdapter.database_exists?(config),
111+
db_config = ActiveRecord::Base.configurations.configs_for(env_name: "arunit", name: "primary")
112+
configuration = db_config.configuration_hash.merge(database: "inexistent_activerecord_unittest")
113+
assert_not ActiveRecord::ConnectionAdapters::SQLServerAdapter.database_exists?(configuration),
111114
"expected database to not exist"
112115
end
113116

114117
it "test database exists returns true when the database exists" do
115-
config = ActiveRecord::Base.configurations["arunit"]
116-
assert ActiveRecord::ConnectionAdapters::SQLServerAdapter.database_exists?(config),
117-
"expected database #{config[:database]} to exist"
118+
db_config = ActiveRecord::Base.configurations.configs_for(env_name: "arunit", name: "primary")
119+
assert ActiveRecord::ConnectionAdapters::SQLServerAdapter.database_exists?(db_config.configuration_hash),
120+
"expected database #{db_config.database} to exist"
118121
end
119122

120123
describe "with different language" do

test/cases/coerced_tests.rb

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,14 +329,18 @@ class QuoteARBaseTest < ActiveRecord::TestCase
329329
coerce_tests! :test_quote_ar_object
330330
def test_quote_ar_object_coerced
331331
value = DatetimePrimaryKey.new(id: @time)
332-
assert_equal "'02-14-2017 12:34:56.79'", @connection.quote(value)
332+
assert_deprecated do
333+
assert_equal "'02-14-2017 12:34:56.79'", @connection.quote(value)
334+
end
333335
end
334336

335337
# Use our date format.
336338
coerce_tests! :test_type_cast_ar_object
337339
def test_type_cast_ar_object_coerced
338340
value = DatetimePrimaryKey.new(id: @time)
339-
assert_equal "02-14-2017 12:34:56.79", @connection.type_cast(value)
341+
assert_deprecated do
342+
assert_equal "02-14-2017 12:34:56.79", @connection.type_cast(value)
343+
end
340344
end
341345
end
342346
end
@@ -896,7 +900,14 @@ def test_reorder_with_take_coerced
896900
coerce_tests! :test_reorder_with_first
897901
def test_reorder_with_first_coerced
898902
sql_log = capture_sql do
899-
assert Post.order(:title).reorder(nil).first
903+
message = <<~MSG.squish
904+
`.reorder(nil)` with `.first` / `.first!` no longer
905+
takes non-deterministic result in Rails 6.2.
906+
To continue taking non-deterministic result, use `.take` / `.take!` instead.
907+
MSG
908+
assert_deprecated(message) do
909+
assert Post.order(:title).reorder(nil).first
910+
end
900911
end
901912
assert sql_log.none? { |sql| /order by [posts].[title]/i.match?(sql) }, "ORDER BY title was used in the query: #{sql_log}"
902913
assert sql_log.all? { |sql| /order by \[posts\]\.\[id\]/i.match?(sql) }, "default ORDER BY ID was not used in the query: #{sql_log}"

0 commit comments

Comments
 (0)