Skip to content

Rails 6.1: remove deprecation warnings #884

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def rename_column(table_name, column_name, new_column_name)
end

def rename_index(table_name, old_name, new_name)
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
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

identifier = SQLServer::Utils.extract_identifiers("#{table_name}.#{old_name}")
execute_procedure :sp_rename, identifier.quoted, new_name, "INDEX"
Expand Down
19 changes: 11 additions & 8 deletions test/cases/adapter_test_sqlserver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ class AdapterTestSQLServer < ActiveRecord::TestCase
assert Topic.table_exists?, "Topics table name of 'dbo.topics' should return true for exists."

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

it "test bad connection" do
assert_raise ActiveRecord::NoDatabaseError do
config = ActiveRecord::Base.configurations["arunit"].merge(database: "inexistent_activerecord_unittest")
ActiveRecord::Base.sqlserver_connection config
db_config = ActiveRecord::Base.configurations.configs_for(env_name: "arunit", name: "primary")
configuration = db_config.configuration_hash.merge(database: "inexistent_activerecord_unittest")
ActiveRecord::Base.sqlserver_connection configuration
end
end

it "test database exists returns false if database does not exist" do
config = ActiveRecord::Base.configurations["arunit"].merge(database: "inexistent_activerecord_unittest")
assert_not ActiveRecord::ConnectionAdapters::SQLServerAdapter.database_exists?(config),
db_config = ActiveRecord::Base.configurations.configs_for(env_name: "arunit", name: "primary")
configuration = db_config.configuration_hash.merge(database: "inexistent_activerecord_unittest")
assert_not ActiveRecord::ConnectionAdapters::SQLServerAdapter.database_exists?(configuration),
"expected database to not exist"
end

it "test database exists returns true when the database exists" do
config = ActiveRecord::Base.configurations["arunit"]
assert ActiveRecord::ConnectionAdapters::SQLServerAdapter.database_exists?(config),
"expected database #{config[:database]} to exist"
db_config = ActiveRecord::Base.configurations.configs_for(env_name: "arunit", name: "primary")
assert ActiveRecord::ConnectionAdapters::SQLServerAdapter.database_exists?(db_config.configuration_hash),
"expected database #{db_config.database} to exist"
end

describe "with different language" do
Expand Down
17 changes: 14 additions & 3 deletions test/cases/coerced_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -329,14 +329,18 @@ class QuoteARBaseTest < ActiveRecord::TestCase
coerce_tests! :test_quote_ar_object
def test_quote_ar_object_coerced
value = DatetimePrimaryKey.new(id: @time)
assert_equal "'02-14-2017 12:34:56.79'", @connection.quote(value)
assert_deprecated do
assert_equal "'02-14-2017 12:34:56.79'", @connection.quote(value)
end
end

# Use our date format.
coerce_tests! :test_type_cast_ar_object
def test_type_cast_ar_object_coerced
value = DatetimePrimaryKey.new(id: @time)
assert_equal "02-14-2017 12:34:56.79", @connection.type_cast(value)
assert_deprecated do
assert_equal "02-14-2017 12:34:56.79", @connection.type_cast(value)
end
end
end
end
Expand Down Expand Up @@ -896,7 +900,14 @@ def test_reorder_with_take_coerced
coerce_tests! :test_reorder_with_first
def test_reorder_with_first_coerced
sql_log = capture_sql do
assert Post.order(:title).reorder(nil).first
message = <<~MSG.squish
`.reorder(nil)` with `.first` / `.first!` no longer
takes non-deterministic result in Rails 6.2.
To continue taking non-deterministic result, use `.take` / `.take!` instead.
MSG
assert_deprecated(message) do
assert Post.order(:title).reorder(nil).first
end
end
assert sql_log.none? { |sql| /order by [posts].[title]/i.match?(sql) }, "ORDER BY title was used in the query: #{sql_log}"
assert sql_log.all? { |sql| /order by \[posts\]\.\[id\]/i.match?(sql) }, "default ORDER BY ID was not used in the query: #{sql_log}"
Expand Down