activerecord-sqlserver-adapter 8.0.10 → 8.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/.devcontainer/Dockerfile +1 -1
  3. data/.github/workflows/ci.yml +34 -3
  4. data/CHANGELOG.md +14 -68
  5. data/Dockerfile.ci +1 -1
  6. data/Gemfile +7 -9
  7. data/Guardfile +2 -2
  8. data/README.md +33 -13
  9. data/Rakefile +1 -1
  10. data/VERSION +1 -1
  11. data/activerecord-sqlserver-adapter.gemspec +15 -16
  12. data/compose.ci.yaml +8 -1
  13. data/lib/active_record/connection_adapters/sqlserver/core_ext/attribute_methods.rb +1 -1
  14. data/lib/active_record/connection_adapters/sqlserver/core_ext/explain.rb +1 -2
  15. data/lib/active_record/connection_adapters/sqlserver/core_ext/explain_subscriber.rb +1 -1
  16. data/lib/active_record/connection_adapters/sqlserver/core_ext/finder_methods.rb +4 -4
  17. data/lib/active_record/connection_adapters/sqlserver/database_statements.rb +118 -83
  18. data/lib/active_record/connection_adapters/sqlserver/database_tasks.rb +3 -4
  19. data/lib/active_record/connection_adapters/sqlserver/quoting.rb +7 -7
  20. data/lib/active_record/connection_adapters/sqlserver/schema_creation.rb +24 -12
  21. data/lib/active_record/connection_adapters/sqlserver/schema_dumper.rb +17 -8
  22. data/lib/active_record/connection_adapters/sqlserver/schema_statements.rb +162 -156
  23. data/lib/active_record/connection_adapters/sqlserver/showplan/printer_table.rb +2 -2
  24. data/lib/active_record/connection_adapters/sqlserver/showplan.rb +5 -5
  25. data/lib/active_record/connection_adapters/sqlserver/sql_type_metadata.rb +2 -7
  26. data/lib/active_record/connection_adapters/sqlserver/table_definition.rb +3 -1
  27. data/lib/active_record/connection_adapters/sqlserver/type/data.rb +3 -3
  28. data/lib/active_record/connection_adapters/sqlserver/type/date.rb +3 -3
  29. data/lib/active_record/connection_adapters/sqlserver/type/datetime.rb +3 -4
  30. data/lib/active_record/connection_adapters/sqlserver/type/smalldatetime.rb +1 -1
  31. data/lib/active_record/connection_adapters/sqlserver/type/time.rb +4 -6
  32. data/lib/active_record/connection_adapters/sqlserver/type/time_value_fractional.rb +1 -1
  33. data/lib/active_record/connection_adapters/sqlserver/type/uuid.rb +0 -2
  34. data/lib/active_record/connection_adapters/sqlserver/utils.rb +10 -12
  35. data/lib/active_record/connection_adapters/sqlserver_adapter.rb +118 -66
  36. data/lib/active_record/connection_adapters/sqlserver_column.rb +17 -9
  37. data/lib/active_record/tasks/sqlserver_database_tasks.rb +5 -5
  38. data/lib/arel/visitors/sqlserver.rb +55 -26
  39. data/test/cases/active_schema_test_sqlserver.rb +45 -23
  40. data/test/cases/adapter_test_sqlserver.rb +72 -59
  41. data/test/cases/coerced_tests.rb +365 -161
  42. data/test/cases/column_test_sqlserver.rb +328 -316
  43. data/test/cases/connection_test_sqlserver.rb +15 -11
  44. data/test/cases/enum_test_sqlserver.rb +8 -9
  45. data/test/cases/execute_procedure_test_sqlserver.rb +1 -1
  46. data/test/cases/fetch_test_sqlserver.rb +1 -1
  47. data/test/cases/helper_sqlserver.rb +7 -3
  48. data/test/cases/index_test_sqlserver.rb +8 -6
  49. data/test/cases/insert_all_test_sqlserver.rb +3 -28
  50. data/test/cases/json_test_sqlserver.rb +8 -8
  51. data/test/cases/lateral_test_sqlserver.rb +2 -2
  52. data/test/cases/migration_test_sqlserver.rb +12 -12
  53. data/test/cases/pessimistic_locking_test_sqlserver.rb +6 -6
  54. data/test/cases/primary_keys_test_sqlserver.rb +4 -4
  55. data/test/cases/rake_test_sqlserver.rb +15 -7
  56. data/test/cases/schema_dumper_test_sqlserver.rb +109 -113
  57. data/test/cases/schema_test_sqlserver.rb +7 -7
  58. data/test/cases/transaction_test_sqlserver.rb +6 -8
  59. data/test/cases/trigger_test_sqlserver.rb +1 -1
  60. data/test/cases/utils_test_sqlserver.rb +3 -3
  61. data/test/cases/view_test_sqlserver.rb +12 -8
  62. data/test/cases/virtual_column_test_sqlserver.rb +113 -0
  63. data/test/migrations/create_clients_and_change_column_collation.rb +2 -2
  64. data/test/models/sqlserver/edge_schema.rb +2 -2
  65. data/test/schema/sqlserver_specific_schema.rb +49 -37
  66. data/test/support/coerceable_test_sqlserver.rb +10 -10
  67. data/test/support/connection_reflection.rb +0 -5
  68. data/test/support/core_ext/backtrace_cleaner.rb +36 -0
  69. data/test/support/query_assertions.rb +6 -6
  70. data/test/support/rake_helpers.rb +6 -10
  71. metadata +12 -107
@@ -15,7 +15,7 @@ class ConnectionTestSQLServer < ActiveRecord::TestCase
15
15
  end
16
16
 
17
17
  it "affect rows" do
18
- topic_data = { 1 => { "content" => "1 updated" }, 2 => { "content" => "2 updated" } }
18
+ topic_data = {1 => {"content" => "1 updated"}, 2 => {"content" => "2 updated"}}
19
19
  updated = Topic.update(topic_data.keys, topic_data.values)
20
20
  assert_equal 2, updated.size
21
21
  assert_equal "1 updated", Topic.find(1).content
@@ -23,16 +23,18 @@ class ConnectionTestSQLServer < ActiveRecord::TestCase
23
23
  assert_equal 2, Topic.delete([1, 2])
24
24
  end
25
25
 
26
- it "allow usage of :database connection option to remove setting from dsn" do
27
- assert_equal "activerecord_unittest", connection.current_database
28
- begin
29
- connection.use_database("activerecord_unittest2")
30
- assert_equal "activerecord_unittest2", connection.current_database
31
- ensure
32
- connection.use_database
33
- assert_equal "activerecord_unittest", connection.current_database, "Would default back to connection options"
26
+ unless connection_sqlserver_azure?
27
+ it "allow usage of :database connection option to remove setting from dsn" do
28
+ assert_equal "activerecord_unittest", connection.current_database
29
+ begin
30
+ connection.use_database("activerecord_unittest2")
31
+ assert_equal "activerecord_unittest2", connection.current_database
32
+ ensure
33
+ connection.use_database
34
+ assert_equal "activerecord_unittest", connection.current_database, "Would default back to connection options"
35
+ end
34
36
  end
35
- end unless connection_sqlserver_azure?
37
+ end
36
38
 
37
39
  describe "Connection management" do
38
40
  it "set spid on connect" do
@@ -60,6 +62,8 @@ class ConnectionTestSQLServer < ActiveRecord::TestCase
60
62
  private
61
63
 
62
64
  def disconnect_raw_connection!
63
- connection.raw_connection.close rescue nil
65
+ connection.raw_connection.close
66
+ rescue
67
+ nil
64
68
  end
65
69
  end
@@ -3,7 +3,6 @@
3
3
  require "cases/helper_sqlserver"
4
4
 
5
5
  class EnumTestSQLServer < ActiveRecord::TestCase
6
-
7
6
  # Check that enums are supported for all string types.
8
7
  # For each type we check: cast, serialize, and update by declaration.
9
8
  # We create a custom class for each type to test.
@@ -11,27 +10,27 @@ class EnumTestSQLServer < ActiveRecord::TestCase
11
10
  describe "support #{col_name} enums" do
12
11
  let(:klass) do
13
12
  Class.new(ActiveRecord::Base) do
14
- self.table_name = 'sst_datatypes'
13
+ self.table_name = "sst_datatypes"
15
14
 
16
- enum col_name, { alpha: "A", beta: "B" }
15
+ enum col_name, {alpha: "A", beta: "B"}
17
16
  end
18
17
  end
19
18
 
20
19
  it "type.cast" do
21
20
  type = klass.type_for_attribute(col_name)
22
21
 
23
- assert_equal "alpha", type.cast('A')
24
- assert_equal "beta", type.cast('B')
22
+ assert_equal "alpha", type.cast("A")
23
+ assert_equal "beta", type.cast("B")
25
24
  end
26
25
 
27
26
  it "type.serialize" do
28
27
  type = klass.type_for_attribute(col_name)
29
28
 
30
- assert_equal 'A', type.serialize('A')
31
- assert_equal 'B', type.serialize('B')
29
+ assert_equal "A", type.serialize("A")
30
+ assert_equal "B", type.serialize("B")
32
31
 
33
- assert_equal 'A', type.serialize(:alpha)
34
- assert_equal 'B', type.serialize(:beta)
32
+ assert_equal "A", type.serialize(:alpha)
33
+ assert_equal "B", type.serialize(:beta)
35
34
  end
36
35
 
37
36
  it "update by declaration" do
@@ -49,7 +49,7 @@ class ExecuteProcedureTestSQLServer < ActiveRecord::TestCase
49
49
  end
50
50
  end
51
51
 
52
- it 'test deprecation with transaction return when executing procedure' do
52
+ it "test deprecation with transaction return when executing procedure" do
53
53
  assert_not_deprecated(ActiveRecord.deprecator) do
54
54
  transaction_with_procedure_and_return
55
55
  end
@@ -49,7 +49,7 @@ class FetchTestSqlserver < ActiveRecord::TestCase
49
49
  query = Book.from(from_sql).order(:id).limit(5)
50
50
 
51
51
  assert_equal query.to_sql, "SELECT [books].* FROM (SELECT [books].* FROM [books]) [books] ORDER BY [books].[id] ASC OFFSET 0 ROWS FETCH NEXT 5 ROWS ONLY"
52
- assert_equal query.to_a.count, 5
52
+ assert_equal query.to_a.size, 5
53
53
  end
54
54
 
55
55
  it "exception thrown if FROM subquery is provided without an order" do
@@ -5,6 +5,7 @@ require "bundler/setup"
5
5
  Bundler.require :default, :development
6
6
  require "pry"
7
7
  require "support/core_ext/query_cache"
8
+ require "support/core_ext/backtrace_cleaner"
8
9
  require "support/minitest_sqlserver"
9
10
  require "support/test_in_memory_oltp"
10
11
  require "support/table_definition_sqlserver"
@@ -16,6 +17,9 @@ require "support/query_assertions"
16
17
  require "mocha/minitest"
17
18
 
18
19
  Minitest.after_run do
20
+ puts "\n\n"
21
+ puts "=" * 80
22
+ puts "Ruby Version: #{RUBY_VERSION}p#{RUBY_PATCHLEVEL} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
19
23
  puts "\n\n"
20
24
  puts "=" * 80
21
25
  puts ActiveRecord::Base.lease_connection.send(:sqlserver_version)
@@ -33,9 +37,9 @@ module ActiveRecord
33
37
  class TestCase < ActiveSupport::TestCase
34
38
  SQLServer = ActiveRecord::ConnectionAdapters::SQLServer
35
39
 
36
- include ARTest::SQLServer::ConnectionReflection,
37
- ActiveSupport::Testing::Stream,
38
- ARTest::SQLServer::QueryAssertions
40
+ include ARTest::SQLServer::QueryAssertions
41
+ include ActiveSupport::Testing::Stream
42
+ include ARTest::SQLServer::ConnectionReflection
39
43
 
40
44
  let(:logger) { ActiveRecord::Base.logger }
41
45
 
@@ -8,27 +8,29 @@ class IndexTestSQLServer < ActiveRecord::TestCase
8
8
  t.column :foo, :string, limit: 100
9
9
  t.column :bar, :string, limit: 100
10
10
  t.string :first_name
11
- t.string :last_name, limit: 100
12
- t.string :key, limit: 100
11
+ t.string :last_name, limit: 100
12
+ t.string :key, limit: 100
13
13
  t.boolean :administrator
14
14
  end
15
15
  end
16
16
 
17
17
  after do
18
- connection.drop_table :testings rescue nil
18
+ connection.drop_table :testings
19
+ rescue
20
+ nil
19
21
  end
20
22
 
21
23
  it "add index with order" do
22
24
  assert_queries_match(/CREATE.*INDEX.*\(\[last_name\] DESC\)/i) do
23
- connection.add_index "testings", ["last_name"], order: { last_name: :desc }
25
+ connection.add_index "testings", ["last_name"], order: {last_name: :desc}
24
26
  connection.remove_index "testings", ["last_name"]
25
27
  end
26
28
  assert_queries_match(/CREATE.*INDEX.*\(\[last_name\] DESC, \[first_name\]\)/i) do
27
- connection.add_index "testings", ["last_name", "first_name"], order: { last_name: :desc }
29
+ connection.add_index "testings", ["last_name", "first_name"], order: {last_name: :desc}
28
30
  connection.remove_index "testings", ["last_name", "first_name"]
29
31
  end
30
32
  assert_queries_match(/CREATE.*INDEX.*\(\[last_name\] DESC, \[first_name\] ASC\)/i) do
31
- connection.add_index "testings", ["last_name", "first_name"], order: { last_name: :desc, first_name: :asc }
33
+ connection.add_index "testings", ["last_name", "first_name"], order: {last_name: :desc, first_name: :asc}
32
34
  connection.remove_index "testings", ["last_name", "first_name"]
33
35
  end
34
36
  end
@@ -1,34 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "cases/helper_sqlserver"
4
- require "models/book"
5
4
  require "models/sqlserver/recurring_task"
6
5
 
7
6
  class InsertAllTestSQLServer < ActiveRecord::TestCase
8
- # Test ported from the Rails `main` branch that is not on the `8-0-stable` branch.
9
- def test_insert_all_only_applies_last_value_when_given_duplicate_identifiers
10
- skip unless supports_insert_on_duplicate_skip?
11
-
12
- Book.insert_all [
13
- { id: 111, name: "expected_new_name" },
14
- { id: 111, name: "unexpected_new_name" }
15
- ]
16
- assert_equal "expected_new_name", Book.find(111).name
17
- end
18
-
19
- # Test ported from the Rails `main` branch that is not on the `8-0-stable` branch.
20
- def test_upsert_all_only_applies_last_value_when_given_duplicate_identifiers
21
- skip unless supports_insert_on_duplicate_update? && !current_adapter?(:PostgreSQLAdapter)
22
-
23
- Book.create!(id: 112, name: "original_name")
24
-
25
- Book.upsert_all [
26
- { id: 112, name: "unexpected_new_name" },
27
- { id: 112, name: "expected_new_name" }
28
- ]
29
- assert_equal "expected_new_name", Book.find(112).name
30
- end
31
-
32
7
  test "upsert_all recording of timestamps works with mixed datatypes" do
33
8
  task = RecurringTask.create!(
34
9
  key: "abcdef",
@@ -36,9 +11,9 @@ class InsertAllTestSQLServer < ActiveRecord::TestCase
36
11
  )
37
12
 
38
13
  RecurringTask.upsert_all([{
39
- id: task.id,
40
- priority: nil
41
- }])
14
+ id: task.id,
15
+ priority: nil
16
+ }])
42
17
 
43
18
  assert_not_equal task.updated_at, RecurringTask.find(task.id).updated_at
44
19
  end
@@ -5,19 +5,19 @@ require "cases/helper_sqlserver"
5
5
  if ActiveRecord::Base.lease_connection.supports_json?
6
6
  class JsonTestSQLServer < ActiveRecord::TestCase
7
7
  before do
8
- @o1 = SSTestDatatypeMigrationJson.create! json_col: { "a" => "a", "b" => "b", "c" => "c" }
9
- @o2 = SSTestDatatypeMigrationJson.create! json_col: { "a" => nil, "b" => "b", "c" => "c" }
10
- @o3 = SSTestDatatypeMigrationJson.create! json_col: { "x" => 1, "y" => 2, "z" => 3 }
11
- @o4 = SSTestDatatypeMigrationJson.create! json_col: { "array" => [1, 2, 3] }
8
+ @o1 = SSTestDatatypeMigrationJson.create! json_col: {"a" => "a", "b" => "b", "c" => "c"}
9
+ @o2 = SSTestDatatypeMigrationJson.create! json_col: {"a" => nil, "b" => "b", "c" => "c"}
10
+ @o3 = SSTestDatatypeMigrationJson.create! json_col: {"x" => 1, "y" => 2, "z" => 3}
11
+ @o4 = SSTestDatatypeMigrationJson.create! json_col: {"array" => [1, 2, 3]}
12
12
  @o5 = SSTestDatatypeMigrationJson.create! json_col: nil
13
13
  end
14
14
 
15
15
  it "can return and save JSON data" do
16
- _(SSTestDatatypeMigrationJson.find(@o1.id).json_col).must_equal({ "a" => "a", "b" => "b", "c" => "c" })
17
- @o1.json_col = { "a" => "a" }
18
- _(@o1.json_col).must_equal({ "a" => "a" })
16
+ _(SSTestDatatypeMigrationJson.find(@o1.id).json_col).must_equal({"a" => "a", "b" => "b", "c" => "c"})
17
+ @o1.json_col = {"a" => "a"}
18
+ _(@o1.json_col).must_equal({"a" => "a"})
19
19
  @o1.save!
20
- _(@o1.reload.json_col).must_equal({ "a" => "a" })
20
+ _(@o1.reload.json_col).must_equal({"a" => "a"})
21
21
  end
22
22
 
23
23
  it "can use ISJSON function" do
@@ -7,7 +7,7 @@ require "models/author"
7
7
  class LateralTestSQLServer < ActiveRecord::TestCase
8
8
  fixtures :posts, :authors
9
9
 
10
- it 'uses OUTER APPLY for OUTER JOIN LATERAL' do
10
+ it "uses OUTER APPLY for OUTER JOIN LATERAL" do
11
11
  post = Arel::Table.new(:posts)
12
12
  author = Arel::Table.new(:authors)
13
13
  subselect = post.project(Arel.star).take(1).where(post[:author_id].eq(author[:id])).where(post[:id].eq(42))
@@ -21,7 +21,7 @@ class LateralTestSQLServer < ActiveRecord::TestCase
21
21
  assert_equal results.length, 1
22
22
  end
23
23
 
24
- it 'uses CROSS APPLY for INNER JOIN LATERAL' do
24
+ it "uses CROSS APPLY for INNER JOIN LATERAL" do
25
25
  post = Arel::Table.new(:posts)
26
26
  author = Arel::Table.new(:authors)
27
27
  subselect = post.project(Arel.star).take(1).where(post[:author_id].eq(author[:id])).where(post[:id].eq(42))
@@ -21,8 +21,8 @@ class MigrationTestSQLServer < ActiveRecord::TestCase
21
21
  begin
22
22
  migrations_dir = File.join ARTest::SQLServer.migrations_root, "transaction_table"
23
23
  quietly { ActiveRecord::MigrationContext.new(migrations_dir).up }
24
- rescue Exception => e
25
- assert_match %r|this and all later migrations canceled|, e.message
24
+ rescue => e
25
+ assert_match %r{this and all later migrations canceled}, e.message
26
26
  end
27
27
  _(connection.tables).wont_include @trans_test_table1
28
28
  _(connection.tables).wont_include @trans_test_table2
@@ -45,9 +45,9 @@ class MigrationTestSQLServer < ActiveRecord::TestCase
45
45
 
46
46
  it "not drop the default constraint if just renaming" do
47
47
  find_default = lambda do
48
- connection.execute_procedure(:sp_helpconstraint, "sst_string_defaults", "nomsg").select do |row|
48
+ connection.execute_procedure(:sp_helpconstraint, "sst_string_defaults", "nomsg").reverse.find do |row|
49
49
  row["constraint_type"] == "DEFAULT on column string_with_pretend_paren_three"
50
- end.last
50
+ end
51
51
  end
52
52
  default_before = find_default.call
53
53
  connection.change_column :sst_string_defaults, :string_with_pretend_paren_three, :string, limit: 255
@@ -68,7 +68,7 @@ class MigrationTestSQLServer < ActiveRecord::TestCase
68
68
  assert_nothing_raised { connection.change_column :sst_string_collation, :string_with_collation, :varchar, collation: :SQL_Latin1_General_CP437_BIN }
69
69
 
70
70
  SstStringCollation.reset_column_information
71
- assert_equal "SQL_Latin1_General_CP437_BIN", SstStringCollation.columns_hash['string_with_collation'].collation
71
+ assert_equal "SQL_Latin1_General_CP437_BIN", SstStringCollation.columns_hash["string_with_collation"].collation
72
72
  end
73
73
  end
74
74
 
@@ -78,7 +78,7 @@ class MigrationTestSQLServer < ActiveRecord::TestCase
78
78
 
79
79
  schemas = connection.exec_query("select name from sys.schemas").to_a
80
80
 
81
- assert_includes schemas, { "name" => "some schema" }
81
+ assert_includes schemas, {"name" => "some schema"}
82
82
  end
83
83
 
84
84
  it "creates a new schema with an owner" do
@@ -86,7 +86,7 @@ class MigrationTestSQLServer < ActiveRecord::TestCase
86
86
 
87
87
  schemas = connection.exec_query("select name, principal_id from sys.schemas").to_a
88
88
 
89
- assert_includes schemas, { "name" => "some schema", "principal_id" => 2 }
89
+ assert_includes schemas, {"name" => "some schema", "principal_id" => 2}
90
90
  end
91
91
  end
92
92
 
@@ -106,18 +106,18 @@ class MigrationTestSQLServer < ActiveRecord::TestCase
106
106
  it "drops a schema" do
107
107
  schemas = connection.exec_query("select name from sys.schemas").to_a
108
108
 
109
- assert_includes schemas, { "name" => "some schema" }
109
+ assert_includes schemas, {"name" => "some schema"}
110
110
 
111
111
  connection.drop_schema("some schema")
112
112
 
113
113
  schemas = connection.exec_query("select name from sys.schemas").to_a
114
114
 
115
- refute_includes schemas, { "name" => "some schema" }
115
+ refute_includes schemas, {"name" => "some schema"}
116
116
  end
117
117
  end
118
118
 
119
- describe 'creating stored procedure' do
120
- it 'stored procedure contains inserts are created successfully' do
119
+ describe "creating stored procedure" do
120
+ it "stored procedure contains inserts are created successfully" do
121
121
  sql = <<-SQL
122
122
  CREATE OR ALTER PROCEDURE do_some_task
123
123
  AS
@@ -126,7 +126,7 @@ class MigrationTestSQLServer < ActiveRecord::TestCase
126
126
  CREATE TABLE SomeTableName (SomeNum int PRIMARY KEY CLUSTERED);
127
127
  INSERT INTO SomeTableName(SomeNum) VALUES(1);
128
128
  END
129
- SQL
129
+ SQL
130
130
 
131
131
  assert_nothing_raised { connection.execute(sql) }
132
132
  ensure
@@ -13,7 +13,7 @@ class PessimisticLockingTestSQLServer < ActiveRecord::TestCase
13
13
  end
14
14
 
15
15
  it "uses with updlock by default" do
16
- assert_queries_match %r|SELECT \[people\]\.\* FROM \[people\] WITH\(UPDLOCK\)| do
16
+ assert_queries_match %r{SELECT \[people\]\.\* FROM \[people\] WITH\(UPDLOCK\)} do
17
17
  _(Person.lock(true).to_a).must_equal Person.all.to_a
18
18
  end
19
19
  end
@@ -47,32 +47,32 @@ class PessimisticLockingTestSQLServer < ActiveRecord::TestCase
47
47
  end
48
48
 
49
49
  it "can add a custom lock directive" do
50
- assert_queries_match %r|SELECT \[people\]\.\* FROM \[people\] WITH\(HOLDLOCK, ROWLOCK\)| do
50
+ assert_queries_match %r{SELECT \[people\]\.\* FROM \[people\] WITH\(HOLDLOCK, ROWLOCK\)} do
51
51
  Person.lock("WITH(HOLDLOCK, ROWLOCK)").load
52
52
  end
53
53
  end
54
54
 
55
55
  describe "joining tables" do
56
56
  it "joined tables use updlock by default" do
57
- assert_queries_match %r|SELECT \[people\]\.\* FROM \[people\] WITH\(UPDLOCK\) INNER JOIN \[readers\] WITH\(UPDLOCK\)\s+ON \[readers\]\.\[person_id\] = \[people\]\.\[id\]| do
57
+ assert_queries_match %r{SELECT \[people\]\.\* FROM \[people\] WITH\(UPDLOCK\) INNER JOIN \[readers\] WITH\(UPDLOCK\)\s+ON \[readers\]\.\[person_id\] = \[people\]\.\[id\]} do
58
58
  Person.lock(true).joins(:readers).load
59
59
  end
60
60
  end
61
61
 
62
62
  it "joined tables can use custom lock directive" do
63
- assert_queries_match %r|SELECT \[people\]\.\* FROM \[people\] WITH\(NOLOCK\) INNER JOIN \[readers\] WITH\(NOLOCK\)\s+ON \[readers\]\.\[person_id\] = \[people\]\.\[id\]| do
63
+ assert_queries_match %r{SELECT \[people\]\.\* FROM \[people\] WITH\(NOLOCK\) INNER JOIN \[readers\] WITH\(NOLOCK\)\s+ON \[readers\]\.\[person_id\] = \[people\]\.\[id\]} do
64
64
  Person.lock("WITH(NOLOCK)").joins(:readers).load
65
65
  end
66
66
  end
67
67
 
68
68
  it "left joined tables use updlock by default" do
69
- assert_queries_match %r|SELECT \[people\]\.\* FROM \[people\] WITH\(UPDLOCK\) LEFT OUTER JOIN \[readers\] WITH\(UPDLOCK\)\s+ON \[readers\]\.\[person_id\] = \[people\]\.\[id\]| do
69
+ assert_queries_match %r{SELECT \[people\]\.\* FROM \[people\] WITH\(UPDLOCK\) LEFT OUTER JOIN \[readers\] WITH\(UPDLOCK\)\s+ON \[readers\]\.\[person_id\] = \[people\]\.\[id\]} do
70
70
  Person.lock(true).left_joins(:readers).load
71
71
  end
72
72
  end
73
73
 
74
74
  it "left joined tables can use custom lock directive" do
75
- assert_queries_match %r|SELECT \[people\]\.\* FROM \[people\] WITH\(NOLOCK\) LEFT OUTER JOIN \[readers\] WITH\(NOLOCK\)\s+ON \[readers\]\.\[person_id\] = \[people\]\.\[id\]| do
75
+ assert_queries_match %r{SELECT \[people\]\.\* FROM \[people\] WITH\(NOLOCK\) LEFT OUTER JOIN \[readers\] WITH\(NOLOCK\)\s+ON \[readers\]\.\[person_id\] = \[people\]\.\[id\]} do
76
76
  Person.lock("WITH(NOLOCK)").left_joins(:readers).load
77
77
  end
78
78
  end
@@ -67,7 +67,7 @@ class PrimaryKeyIntegerTest < ActiveRecord::TestCase
67
67
  assert_not_predicate column, :bigint?
68
68
 
69
69
  schema = dump_table_schema "widgets"
70
- assert_match %r/create_table "widgets", id: :integer, force: :cascade do/, schema
70
+ assert_match %r{create_table "widgets", id: :integer, force: :cascade do}, schema
71
71
  end
72
72
 
73
73
  test "bigint primary key without default" do
@@ -79,7 +79,7 @@ class PrimaryKeyIntegerTest < ActiveRecord::TestCase
79
79
  assert_predicate column, :bigint?
80
80
 
81
81
  schema = dump_table_schema "widgets"
82
- assert_match %r/create_table "widgets", force: :cascade do/, schema
82
+ assert_match %r{create_table "widgets", force: :cascade do}, schema
83
83
  end
84
84
 
85
85
  test "don't set identity to integer and bigint when there is a default" do
@@ -91,13 +91,13 @@ class PrimaryKeyIntegerTest < ActiveRecord::TestCase
91
91
  assert_not_predicate column, :is_identity?
92
92
 
93
93
  schema = dump_table_schema "widgets"
94
- assert_match %r/create_table "widgets", id: :bigint, default: nil, force: :cascade do/, schema
94
+ assert_match %r{create_table "widgets", id: :bigint, default: nil, force: :cascade do}, schema
95
95
 
96
96
  column = @connection.columns(:barcodes).find { |c| c.name == "id" }
97
97
  assert_predicate column, :is_primary?
98
98
  assert_not_predicate column, :is_identity?
99
99
 
100
100
  schema = dump_table_schema "barcodes"
101
- assert_match %r/create_table "barcodes", id: :integer, default: nil, force: :cascade do/, schema
101
+ assert_match %r{create_table "barcodes", id: :integer, default: nil, force: :cascade do}, schema
102
102
  end
103
103
  end
@@ -8,15 +8,15 @@ class SQLServerRakeTest < ActiveRecord::TestCase
8
8
  cattr_accessor :azure_skip
9
9
  self.azure_skip = connection_sqlserver_azure?
10
10
 
11
- let(:db_tasks) { ActiveRecord::Tasks::DatabaseTasks }
12
- let(:new_database) { "activerecord_unittest_tasks" }
11
+ let(:db_tasks) { ActiveRecord::Tasks::DatabaseTasks }
12
+ let(:new_database) { "activerecord_unittest_tasks" }
13
13
  let(:default_configuration) { ARTest.test_configuration_hashes["arunit"] }
14
- let(:configuration) { default_configuration.merge("database" => new_database) }
15
- let(:db_config) { ActiveRecord::Base.configurations.resolve(configuration) }
14
+ let(:configuration) { default_configuration.merge("database" => new_database) }
15
+ let(:db_config) { ActiveRecord::Base.configurations.resolve(configuration) }
16
16
 
17
17
  before { skip "on azure" if azure_skip }
18
18
  before { disconnect! unless azure_skip }
19
- after { reconnect unless azure_skip }
19
+ after { reconnect unless azure_skip }
20
20
 
21
21
  private
22
22
 
@@ -28,12 +28,20 @@ class SQLServerRakeTest < ActiveRecord::TestCase
28
28
  config = default_configuration
29
29
  if connection_sqlserver_azure?
30
30
  ActiveRecord::Base.establish_connection(config.merge("database" => "master"))
31
- connection.drop_database(new_database) rescue nil
31
+ begin
32
+ connection.drop_database(new_database)
33
+ rescue
34
+ nil
35
+ end
32
36
  disconnect!
33
37
  ActiveRecord::Base.establish_connection(config)
34
38
  else
35
39
  ActiveRecord::Base.establish_connection(config)
36
- connection.drop_database(new_database) rescue nil
40
+ begin
41
+ connection.drop_database(new_database)
42
+ rescue
43
+ nil
44
+ end
37
45
  end
38
46
  end
39
47
  end