activerecord-sqlserver-adapter 7.2.7 → 8.0.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.
@@ -376,18 +376,6 @@ module ActiveRecord
376
376
  end
377
377
 
378
378
  class CalculationsTest < ActiveRecord::TestCase
379
- # SELECT columns must be in the GROUP clause.
380
- coerce_tests! :test_should_count_with_group_by_qualified_name_on_loaded
381
- def test_should_count_with_group_by_qualified_name_on_loaded_coerced
382
- accounts = Account.group("accounts.id").select("accounts.id")
383
- expected = { 1 => 1, 2 => 1, 3 => 1, 4 => 1, 5 => 1, 6 => 1 }
384
- assert_not_predicate accounts, :loaded?
385
- assert_equal expected, accounts.count
386
- accounts.load
387
- assert_predicate accounts, :loaded?
388
- assert_equal expected, accounts.count(:id)
389
- end
390
-
391
379
  # Fix randomly failing test. The loading of the model's schema was affecting the test.
392
380
  coerce_tests! :test_offset_is_kept
393
381
  def test_offset_is_kept_coerced
@@ -532,6 +520,9 @@ class CalculationsTest < ActiveRecord::TestCase
532
520
 
533
521
  # SELECT columns must be in the GROUP clause. Since since `ids` only selects the primary key you cannot perform this query in SQL Server.
534
522
  coerce_tests! :test_ids_with_includes_and_non_primary_key_order
523
+
524
+ # To limit the results in SQL Server we use `FETCH NEXT @0 ROWS ONLY` instead of `LIMIT @0`. To use `FETCH NEXT` an order must be provided.
525
+ coerce_tests! :test_no_order_by_when_counting_all
535
526
  end
536
527
 
537
528
  module ActiveRecord
@@ -1349,6 +1340,20 @@ module ActiveRecord
1349
1340
  def test_registering_new_handlers_for_association_coerced
1350
1341
  assert_match %r{#{Regexp.escape(topic_title)} ~ N'rails'}i, Reply.joins(:topic).where(topics: { title: /rails/ }).to_sql
1351
1342
  end
1343
+
1344
+ # Same as original test except string has `N` prefix to indicate unicode string.
1345
+ coerce_tests! :test_registering_new_handlers_for_joins
1346
+ def test_registering_new_handlers_for_joins_coerced
1347
+ Reply.belongs_to :regexp_topic, -> { where(title: /rails/) }, class_name: "Topic", foreign_key: "parent_id"
1348
+
1349
+ assert_match %r{#{Regexp.escape(quote_table_name("regexp_topic.title"))} ~ N'rails'}i, Reply.joins(:regexp_topic).references(Arel.sql("regexp_topic")).to_sql
1350
+ end
1351
+
1352
+ private
1353
+
1354
+ def topic_title
1355
+ Topic.lease_connection.quote_table_name("topics.title")
1356
+ end
1352
1357
  end
1353
1358
  end
1354
1359
 
@@ -2180,17 +2185,6 @@ class EnumTest < ActiveRecord::TestCase
2180
2185
  Book.lease_connection.add_index(:books, [:author_id, :name], unique: true)
2181
2186
  end
2182
2187
 
2183
- # Need to remove index as SQL Server considers NULLs on a unique-index to be equal unlike PostgreSQL/MySQL/SQLite.
2184
- coerce_tests! %r{declare multiple enums at a time}
2185
- test "declare multiple enums at a time coerced" do
2186
- Book.lease_connection.remove_index(:books, column: [:author_id, :name])
2187
-
2188
- send(:'original_declare multiple enums at a time')
2189
- ensure
2190
- Book.where(author_id: nil, name: nil).delete_all
2191
- Book.lease_connection.add_index(:books, [:author_id, :name], unique: true)
2192
- end
2193
-
2194
2188
  # Need to remove index as SQL Server considers NULLs on a unique-index to be equal unlike PostgreSQL/MySQL/SQLite.
2195
2189
  coerce_tests! %r{serializable\? with large number label}
2196
2190
  test "serializable? with large number label coerced" do
@@ -2262,14 +2256,6 @@ class LogSubscriberTest < ActiveRecord::TestCase
2262
2256
  def test_verbose_query_logs_coerced
2263
2257
  original_test_verbose_query_logs
2264
2258
  end
2265
-
2266
- # Bindings logged slightly differently.
2267
- coerce_tests! :test_where_in_binds_logging_include_attribute_names
2268
- def test_where_in_binds_logging_include_attribute_names_coerced
2269
- Developer.where(id: [1, 2, 3, 4, 5]).load
2270
- wait
2271
- assert_match(%{@0 = 1, @1 = 2, @2 = 3, @3 = 4, @4 = 5 [["id", nil], ["id", nil], ["id", nil], ["id", nil], ["id", nil]]}, @logger.logged(:debug).last)
2272
- end
2273
2259
  end
2274
2260
 
2275
2261
  class ReloadModelsTest < ActiveRecord::TestCase
@@ -2431,7 +2417,9 @@ class QueryLogsTest < ActiveRecord::TestCase
2431
2417
  # SQL requires double single-quotes.
2432
2418
  coerce_tests! :test_sql_commenter_format
2433
2419
  def test_sql_commenter_format_coerced
2434
- ActiveRecord::QueryLogs.update_formatter(:sqlcommenter)
2420
+ ActiveRecord::QueryLogs.tags_formatter = :sqlcommenter
2421
+ ActiveRecord::QueryLogs.tags = [:application]
2422
+
2435
2423
  assert_queries_match(%r{/\*application=''active_record''\*/}) do
2436
2424
  Dashboard.first
2437
2425
  end
@@ -2440,7 +2428,7 @@ class QueryLogsTest < ActiveRecord::TestCase
2440
2428
  # SQL requires double single-quotes.
2441
2429
  coerce_tests! :test_sqlcommenter_format_value
2442
2430
  def test_sqlcommenter_format_value_coerced
2443
- ActiveRecord::QueryLogs.update_formatter(:sqlcommenter)
2431
+ ActiveRecord::QueryLogs.tags_formatter = :sqlcommenter
2444
2432
 
2445
2433
  ActiveRecord::QueryLogs.tags = [
2446
2434
  :application,
@@ -2455,7 +2443,7 @@ class QueryLogsTest < ActiveRecord::TestCase
2455
2443
  # SQL requires double single-quotes.
2456
2444
  coerce_tests! :test_sqlcommenter_format_value_string_coercible
2457
2445
  def test_sqlcommenter_format_value_string_coercible_coerced
2458
- ActiveRecord::QueryLogs.update_formatter(:sqlcommenter)
2446
+ ActiveRecord::QueryLogs.tags_formatter = :sqlcommenter
2459
2447
 
2460
2448
  ActiveRecord::QueryLogs.tags = [
2461
2449
  :application,
@@ -2470,7 +2458,7 @@ class QueryLogsTest < ActiveRecord::TestCase
2470
2458
  # SQL requires double single-quotes.
2471
2459
  coerce_tests! :test_sqlcommenter_format_allows_string_keys
2472
2460
  def test_sqlcommenter_format_allows_string_keys_coerced
2473
- ActiveRecord::QueryLogs.update_formatter(:sqlcommenter)
2461
+ ActiveRecord::QueryLogs.tags_formatter = :sqlcommenter
2474
2462
 
2475
2463
  ActiveRecord::QueryLogs.tags = [
2476
2464
  :application,
@@ -2505,6 +2493,17 @@ class InsertAllTest < ActiveRecord::TestCase
2505
2493
  result = Book.insert_all! [{ name: "Rework", author_id: 1 }], returning: Arel.sql("UPPER(INSERTED.name) as name")
2506
2494
  assert_equal %w[ REWORK ], result.pluck("name")
2507
2495
  end
2496
+
2497
+ # Need to remove index as SQL Server considers NULLs on a unique-index to be equal unlike PostgreSQL/MySQL/SQLite.
2498
+ coerce_tests! :test_insert_with_type_casting_and_serialize_is_consistent
2499
+ def test_insert_with_type_casting_and_serialize_is_consistent_coerced
2500
+ connection.remove_index(:books, column: [:author_id, :name])
2501
+
2502
+ original_test_insert_with_type_casting_and_serialize_is_consistent
2503
+ ensure
2504
+ Book.where(author_id: nil, name: '["Array"]').delete_all
2505
+ Book.lease_connection.add_index(:books, [:author_id, :name], unique: true)
2506
+ end
2508
2507
  end
2509
2508
 
2510
2509
  module ActiveRecord
@@ -2667,6 +2666,28 @@ module ActiveRecord
2667
2666
  end
2668
2667
  end
2669
2668
 
2669
+ module ActiveRecord
2670
+ module ConnectionAdapters
2671
+ class RegistrationIsolatedTest < ActiveRecord::TestCase
2672
+ # SQL Server was not included in the list of available adapters in the error message.
2673
+ coerce_tests! %r{resolve raises if the adapter is using the pre 7.2 adapter registration API}
2674
+ def resolve_raises_if_the_adapter_is_using_the_pre_7_2_adapter_registration_API
2675
+ exception = assert_raises(ActiveRecord::AdapterNotFound) do
2676
+ ActiveRecord::ConnectionAdapters.resolve("fake_legacy")
2677
+ end
2678
+
2679
+ assert_equal(
2680
+ "Database configuration specifies nonexistent 'ridiculous' adapter. Available adapters are: abstract, fake, mysql2, postgresql, sqlite3, sqlserver, trilogy. Ensure that the adapter is spelled correctly in config/database.yml and that you've added the necessary adapter gem to your Gemfile if it's not in the list of available adapters.",
2681
+ exception.message
2682
+ )
2683
+ ensure
2684
+ ActiveRecord::ConnectionAdapters.instance_variable_get(:@adapters).delete("fake_legacy")
2685
+ end
2686
+ end
2687
+ end
2688
+ end
2689
+
2690
+
2670
2691
  module ActiveRecord
2671
2692
  class TableMetadataTest < ActiveSupport::TestCase
2672
2693
  # Adapter returns an object that is subclass of what is expected in the original test.
@@ -36,7 +36,6 @@ class OptimizerHitsTestSQLServer < ActiveRecord::TestCase
36
36
  end
37
37
  end
38
38
 
39
-
40
39
  it "support order" do
41
40
  assert_queries_match(%r{\ASELECT .+ FROM .+ ORDER .+ OPTION .+\z}) do
42
41
  companies = Company.optimizer_hints("LABEL='FindCompanies'")
@@ -101,11 +101,5 @@ class SchemaTestSQLServer < ActiveRecord::TestCase
101
101
  assert_equal "[with].[select notation]", connection.send(:get_raw_table_name, "INSERT INTO [with].[select notation] SELECT * FROM [table_name]")
102
102
  end
103
103
  end
104
-
105
- describe 'CREATE VIEW statements' do
106
- it do
107
- assert_equal "test_table_as", connection.send(:get_raw_table_name, "CREATE VIEW test_views ( test_table_a_id, test_table_b_id ) AS SELECT test_table_as.id as test_table_a_id, test_table_bs.id as test_table_b_id FROM (test_table_as with(nolock) LEFT JOIN test_table_bs with(nolock) ON (test_table_as.id = test_table_bs.test_table_a_id))")
108
- end
109
- end
110
104
  end
111
105
  end
@@ -48,17 +48,11 @@ class ViewTestSQLServer < ActiveRecord::TestCase
48
48
  end
49
49
  end
50
50
 
51
- describe "identity insert" do
52
- it "creates table record through a view" do
53
- assert_difference("SSTestCustomersView.count", 2) do
51
+ describe 'identity insert' do
52
+ it "identity insert works with views" do
53
+ assert_difference("SSTestCustomersView.count", 1) do
54
54
  SSTestCustomersView.create!(id: 5, name: "Bob")
55
- SSTestCustomersView.create!(id: 6, name: "Tim")
56
55
  end
57
56
  end
58
-
59
- it "creates table records through a view using fixtures" do
60
- ActiveRecord::FixtureSet.create_fixtures(File.join(ARTest::SQLServer.test_root_sqlserver, "fixtures"), ["sst_customers_view"])
61
- assert_equal SSTestCustomersView.all.count, 2
62
- end
63
57
  end
64
58
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-sqlserver-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.2.7
4
+ version: 8.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ken Collins
@@ -12,9 +12,10 @@ authors:
12
12
  - Joe Rafaniello
13
13
  - Tom Ward
14
14
  - Aidan Haran
15
+ autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
- date: 1980-01-02 00:00:00.000000000 Z
18
+ date: 2024-11-11 00:00:00.000000000 Z
18
19
  dependencies:
19
20
  - !ruby/object:Gem::Dependency
20
21
  name: activerecord
@@ -22,14 +23,14 @@ dependencies:
22
23
  requirements:
23
24
  - - "~>"
24
25
  - !ruby/object:Gem::Version
25
- version: 7.2.0
26
+ version: 8.0.0
26
27
  type: :runtime
27
28
  prerelease: false
28
29
  version_requirements: !ruby/object:Gem::Requirement
29
30
  requirements:
30
31
  - - "~>"
31
32
  - !ruby/object:Gem::Version
32
- version: 7.2.0
33
+ version: 8.0.0
33
34
  - !ruby/object:Gem::Dependency
34
35
  name: tiny_tds
35
36
  requirement: !ruby/object:Gem::Requirement
@@ -78,7 +79,6 @@ files:
78
79
  - lib/active_record/connection_adapters/sqlserver/core_ext/abstract_adapter.rb
79
80
  - lib/active_record/connection_adapters/sqlserver/core_ext/active_record.rb
80
81
  - lib/active_record/connection_adapters/sqlserver/core_ext/attribute_methods.rb
81
- - lib/active_record/connection_adapters/sqlserver/core_ext/calculations.rb
82
82
  - lib/active_record/connection_adapters/sqlserver/core_ext/explain.rb
83
83
  - lib/active_record/connection_adapters/sqlserver/core_ext/explain_subscriber.rb
84
84
  - lib/active_record/connection_adapters/sqlserver/core_ext/finder_methods.rb
@@ -176,8 +176,6 @@ files:
176
176
  - test/cases/schema_test_sqlserver.rb
177
177
  - test/cases/showplan_test_sqlserver.rb
178
178
  - test/cases/specific_schema_test_sqlserver.rb
179
- - test/cases/temp_test_sqlserver.rb
180
- - test/cases/temporary_table_test_sqlserver.rb
181
179
  - test/cases/transaction_test_sqlserver.rb
182
180
  - test/cases/trigger_test_sqlserver.rb
183
181
  - test/cases/utils_test_sqlserver.rb
@@ -186,7 +184,6 @@ files:
186
184
  - test/config.yml
187
185
  - test/debug.rb
188
186
  - test/fixtures/1px.gif
189
- - test/fixtures/sst_customers_view.yml
190
187
  - test/migrations/create_clients_and_change_column_collation.rb
191
188
  - test/migrations/create_clients_and_change_column_null.rb
192
189
  - test/migrations/transaction_table/1_table_will_never_be_created.rb
@@ -241,8 +238,9 @@ licenses:
241
238
  - MIT
242
239
  metadata:
243
240
  bug_tracker_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/issues
244
- changelog_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blob/v7.2.7/CHANGELOG.md
245
- source_code_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/v7.2.7
241
+ changelog_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blob/v8.0.0/CHANGELOG.md
242
+ source_code_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/v8.0.0
243
+ post_install_message:
246
244
  rdoc_options: []
247
245
  require_paths:
248
246
  - lib
@@ -250,14 +248,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
250
248
  requirements:
251
249
  - - ">="
252
250
  - !ruby/object:Gem::Version
253
- version: 3.1.0
251
+ version: 3.2.0
254
252
  required_rubygems_version: !ruby/object:Gem::Requirement
255
253
  requirements:
256
254
  - - ">="
257
255
  - !ruby/object:Gem::Version
258
256
  version: '0'
259
257
  requirements: []
260
- rubygems_version: 3.6.7
258
+ rubygems_version: 3.5.21
259
+ signing_key:
261
260
  specification_version: 4
262
261
  summary: ActiveRecord SQL Server Adapter.
263
262
  test_files:
@@ -295,8 +294,6 @@ test_files:
295
294
  - test/cases/schema_test_sqlserver.rb
296
295
  - test/cases/showplan_test_sqlserver.rb
297
296
  - test/cases/specific_schema_test_sqlserver.rb
298
- - test/cases/temp_test_sqlserver.rb
299
- - test/cases/temporary_table_test_sqlserver.rb
300
297
  - test/cases/transaction_test_sqlserver.rb
301
298
  - test/cases/trigger_test_sqlserver.rb
302
299
  - test/cases/utils_test_sqlserver.rb
@@ -305,7 +302,6 @@ test_files:
305
302
  - test/config.yml
306
303
  - test/debug.rb
307
304
  - test/fixtures/1px.gif
308
- - test/fixtures/sst_customers_view.yml
309
305
  - test/migrations/create_clients_and_change_column_collation.rb
310
306
  - test/migrations/create_clients_and_change_column_null.rb
311
307
  - test/migrations/transaction_table/1_table_will_never_be_created.rb
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "active_record/relation"
4
- require "active_record/version"
5
-
6
- module ActiveRecord
7
- module ConnectionAdapters
8
- module SQLServer
9
- module CoreExt
10
- module Calculations
11
-
12
- private
13
-
14
- def build_count_subquery(relation, column_name, distinct)
15
- klass.with_connection do |connection|
16
- relation = relation.unscope(:order) if connection.sqlserver?
17
- super(relation, column_name, distinct)
18
- end
19
- end
20
- end
21
- end
22
- end
23
- end
24
- end
25
-
26
- ActiveSupport.on_load(:active_record) do
27
- mod = ActiveRecord::ConnectionAdapters::SQLServer::CoreExt::Calculations
28
- ActiveRecord::Relation.include(mod)
29
- end
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "cases/helper_sqlserver"
4
-
5
- class TempTestSQLServer < ActiveRecord::TestCase
6
- # it "assert true" do
7
- # assert true
8
- # end
9
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "cases/helper_sqlserver"
4
-
5
- class TemporaryTableSQLServer < ActiveRecord::TestCase
6
- def test_insert_into_temporary_table
7
- ActiveRecord::Base.with_connection do |conn|
8
- conn.exec_query("CREATE TABLE #temp_users (id INT IDENTITY(1,1), name NVARCHAR(100))")
9
-
10
- result = conn.exec_query("SELECT * FROM #temp_users")
11
- assert_equal 0, result.count
12
-
13
- conn.exec_query("INSERT INTO #temp_users (name) VALUES ('John'), ('Doe')")
14
-
15
- result = conn.exec_query("SELECT * FROM #temp_users")
16
- assert_equal 2, result.count
17
- end
18
- end
19
- end
@@ -1,6 +0,0 @@
1
- david:
2
- name: "David"
3
- balance: 2,004
4
- aidan:
5
- name: "Aidan"
6
- balance: 10,191