Skip to content
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
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ end

group :development do
gem "minitest-spec-rails"
gem "mocha"
gem "pry-byebug", platform: [:mri, :mingw, :x64_mingw]
end

Expand Down
72 changes: 27 additions & 45 deletions test/cases/coerced_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,6 @@ def test_truncate_tables_with_query_cache_coerced
# Restore foreign key constraint.
@connection.add_foreign_key :authors, :author_addresses
end

# SQL Server does not allow truncation of tables that are referenced by foreign key
# constraints. As this test truncates all tables we would need to remove all foreign
# key constraints and then restore them afterwards to get this test to pass.
coerce_tests! :test_empty_all_tables, :test_empty_all_tables_with_query_cache
end
end

Expand Down Expand Up @@ -2013,13 +2008,32 @@ class SchemaCacheTest < ActiveRecord::TestCase
# Tests fail on Windows AppVeyor CI with 'Permission denied' error when renaming file during `File.atomic_write` call.
coerce_tests! :test_yaml_dump_and_load, :test_yaml_dump_and_load_with_gzip if /mswin|mingw/.match?(RbConfig::CONFIG["host_os"])

# Cast type in SQL Server is :varchar rather than Unicode :string.
coerce_tests! :test_yaml_load_8_0_dump_without_cast_type_still_get_the_right_one
def test_yaml_load_8_0_dump_without_cast_type_still_get_the_right_one
cache = load_bound_reflection(schema_dump_8_0_path)

assert_no_queries do
columns = cache.columns_hash("courses")
assert_equal 3, columns.size
cast_type = columns["name"].fetch_cast_type(@connection)
assert_not_nil cast_type, "expected cast_type to be present"
assert_equal :varchar, cast_type.type
end
end

private

# We need to give the full paths for this to work.
undef_method :schema_dump_5_1_path
def schema_dump_5_1_path
File.join(ARTest::SQLServer.root_activerecord, "test/assets/schema_dump_5_1.yml")
end

undef_method :schema_dump_8_0_path
def schema_dump_8_0_path
File.join(ARTest::SQLServer.root_activerecord, "test/assets/schema_dump_8_0.yml")
end
end
end
end
Expand Down Expand Up @@ -2448,17 +2462,6 @@ def test_in_order_of_with_nil_coerced
Book.lease_connection.add_index(:books, [:author_id, :name], unique: true)
end

# Need to remove index as SQL Server considers NULLs on a unique-index to be equal unlike PostgreSQL/MySQL/SQLite.
coerce_tests! :test_in_order_of_with_array_values_with_nil
def test_in_order_of_with_array_values_with_nil_coerced
Book.lease_connection.remove_index(:books, column: [:author_id, :name])

original_test_in_order_of_with_array_values_with_nil
ensure
Book.where(author_id: nil, name: nil).delete_all
Book.lease_connection.add_index(:books, [:author_id, :name], unique: true)
end

# Need to remove index as SQL Server considers NULLs on a unique-index to be equal unlike PostgreSQL/MySQL/SQLite.
coerce_tests! :test_in_order_of_with_out_of_bound_integer_does_not_match_nulls
def test_in_order_of_with_out_of_bound_integer_does_not_match_nulls_coerced
Expand Down Expand Up @@ -2764,12 +2767,12 @@ def test_assert_queries_match_coerced
error = assert_raises(Minitest::Assertion) {
assert_queries_match(/ASC OFFSET 0 ROWS FETCH NEXT @0 ROWS ONLY/i, count: 2) { Post.first }
}
assert_match(/1 instead of 2 matching queries/, error.message)
assert_match(/1 instead of 2 queries/, error.message)

error = assert_raises(Minitest::Assertion) {
assert_queries_match(/ASC OFFSET 0 ROWS FETCH NEXT @0 ROWS ONLY/i, count: 0) { Post.first }
}
assert_match(/1 instead of 0 matching queries/, error.message)
assert_match(/1 instead of 0 queries/, error.message)
end
end
end
Expand Down Expand Up @@ -2898,33 +2901,12 @@ def test_in_batches_loaded_should_unscope_cursor_after_pluck_coerced
end
end

class TransactionInstrumentationTest < ActiveRecord::TestCase
# SQL Server does not have query for release_savepoint.
coerce_tests! :test_sql_events_do_not_overlap_with_savepoints
def test_sql_events_do_not_overlap_with_savepoints_coerced
events = []
subscriber = ActiveSupport::Notifications.subscribe("sql.active_record") do |event|
events << event
end
class ActiveRecord::Encryption::EncryptableFixtureTest < ActiveRecord::EncryptionTestCase
# Set the attribute as JSON type.
::EncryptedBookWithJson.attribute :metadata, ActiveRecord::Type::SQLServer::Json.new

Topic.transaction do
Topic.count
Topic.transaction(requires_new: true) { Topic.first }
end

assert_equal 5, events.size
begin_event, count_event, savepoint_event, select_event, commit_event = events

assert begin_event.payload[:sql].start_with?("BEGIN")
assert count_event.payload[:sql].start_with?("SELECT")
assert savepoint_event.payload[:sql].start_with?("SAVE TRANSACTION")
assert select_event.payload[:sql].start_with?("SELECT")
assert commit_event.payload[:sql].start_with?("COMMIT")

events.each_cons(2) do |a, b|
assert_operator a.end, :<=, b.time
end
ensure
ActiveSupport::Notifications.unsubscribe(subscriber)
coerce_tests! %r{fixtures for json columns get encrypted automatically}
def fixtures_for_json_columns_get_encrypted_automatically
send(:"original_fixtures for json columns get encrypted automatically")
end
end
10 changes: 4 additions & 6 deletions test/cases/dbconsole_test_sqlserver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ class DbConsole < ActiveRecord::TestCase
subject { ActiveRecord::ConnectionAdapters::SQLServerAdapter }

it "uses sqlcmd to connect to database" do
subject.expects(:find_cmd_and_exec).with("sqlcmd", "-d", "db", "-U", "user", "-P", "secret", "-C", "-S",
"tcp:localhost,1433")
assert_called_with(subject, :find_cmd_and_exec, ["sqlcmd", "-d", "db", "-U", "user", "-P", "secret", "-C", "-S", "tcp:localhost,1433"]) do
config = make_db_config(adapter: "sqlserver", database: "db", username: "user", password: "secret", host: "localhost", port: 1433, trust_server_certificate: true)

config = make_db_config(adapter: "sqlserver", database: "db", username: "user", password: "secret",
host: "localhost", port: 1433, trust_server_certificate: true)

subject.dbconsole(config)
subject.dbconsole(config)
end
end

private
Expand Down
1 change: 0 additions & 1 deletion test/cases/helper_sqlserver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
require "support/coerceable_test_sqlserver"
require "support/connection_reflection"
require "support/query_assertions"
require "mocha/minitest"

Minitest.after_run do
puts "\n\n"
Expand Down
Loading