torque-postgresql 3.3.3 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7afebc02d5b903b8ddb8cfdee36ff8260d1c82977943f2fadbb63771902c6c44
4
- data.tar.gz: 89a55ffc034942f5b49dac3693fc3ed95fc6a0d49a01586c2b58a0c26086e2de
3
+ metadata.gz: 84962b5a78fc9b09f10f35c091e90ec83e71786a8e6b98d2e88468376b7fc20e
4
+ data.tar.gz: 4637773971675c9381075895134efc16e0589ec7b4a4219e92bd7b6e6a34eb5d
5
5
  SHA512:
6
- metadata.gz: 168d3558d8ba7ac6862b39301381edcfd23a208bfd24293fc957a53243327b561d1063fc794bbedf741bcca12cd6fd3f3460999b3674300ed6f1171e510fcc51
7
- data.tar.gz: '09859ddf3c06760d276fe25df11e8817168115cbea4ce971b86884ef3ed39428cc0292a885c10300e720d9a1b2f1c3da35dff40532f24fab96f13bb4b122f19c'
6
+ metadata.gz: f36770306242b9bfce00fa8216080be72970ec2b69f3f1b3e98dbf30151f1017699a0d3f9c731154b60ecddba17cd382e56e116edaf701aa2549dc25a9ab000f
7
+ data.tar.gz: 9ecbd264e042f773a9e93bf414a233932ec4ed5663125894f2e3011d0a6f1c829f41fdbdee3f30ed891df2bfe9adce174dd7bfd29eb2bbe615c31a4bf124a787
@@ -24,7 +24,7 @@ module Torque
24
24
  end
25
25
 
26
26
  def connected_through_array?
27
- !association_key_name.is_a?(Array) && foreign_column.array?
27
+ !association_key_name.is_a?(Array) && foreign_column&.array?
28
28
  end
29
29
  end
30
30
 
@@ -201,9 +201,11 @@ module Torque
201
201
  end
202
202
 
203
203
  # Allow extra keyword arguments to be sent to +InsertAll+
204
- def upsert_all(attributes, **xargs)
205
- xargs = xargs.merge(on_duplicate: :update)
206
- ::ActiveRecord::InsertAll.new(self, attributes, **xargs).execute
204
+ unless Torque::PostgreSQL::AR720
205
+ def upsert_all(attributes, **xargs)
206
+ xargs = xargs.reverse_merge(on_duplicate: :update)
207
+ ::ActiveRecord::InsertAll.new(self, attributes, **xargs).execute
208
+ end
207
209
  end
208
210
 
209
211
  protected
@@ -6,6 +6,7 @@ module Torque
6
6
 
7
7
  # Stores a version check for compatibility purposes
8
8
  AR710 = (ActiveRecord.gem_version >= Gem::Version.new('7.1.0'))
9
+ AR720 = (ActiveRecord.gem_version >= Gem::Version.new('7.2.0'))
9
10
 
10
11
  # Use the same logger as the Active Record one
11
12
  def self.logger
@@ -102,7 +102,7 @@ module Torque
102
102
  # Compatibility method with 5.0
103
103
  unless ActiveRecord::Relation.method_defined?(:set_value)
104
104
  def set_value(name, value)
105
- assert_mutability!
105
+ assert_mutability! if respond_to?(:assert_mutability!)
106
106
  @values[name] = value
107
107
  end
108
108
  end
@@ -133,6 +133,14 @@ module Torque
133
133
  klass.superclass.send(:relation) if klass.define_attribute_methods &&
134
134
  klass.superclass != ActiveRecord::Base && !klass.superclass.abstract_class?
135
135
  end
136
+
137
+ # Allow extra keyword arguments to be sent to +InsertAll+
138
+ if Torque::PostgreSQL::AR720
139
+ def upsert_all(attributes, **xargs)
140
+ xargs = xargs.reverse_merge(on_duplicate: :update)
141
+ ::ActiveRecord::InsertAll.execute(self, attributes, **xargs)
142
+ end
143
+ end
136
144
  end
137
145
  end
138
146
 
@@ -4,19 +4,23 @@ module Torque
4
4
  module PostgreSQL
5
5
  module BoundSchemaReflection
6
6
  def add_model_name(table_name, model)
7
- @schema_reflection.add_model_name(@connection, table_name, model)
7
+ source = defined?(@pool) ? @pool : @connection
8
+ @schema_reflection.add_model_name(source, table_name, model)
8
9
  end
9
10
 
10
11
  def dependencies(table_name)
11
- @schema_reflection.dependencies(@connection, table_name)
12
+ source = defined?(@pool) ? @pool : @connection
13
+ @schema_reflection.dependencies(source, table_name)
12
14
  end
13
15
 
14
16
  def associations(table_name)
15
- @schema_reflection.associations(@connection, table_name)
17
+ source = defined?(@pool) ? @pool : @connection
18
+ @schema_reflection.associations(source, table_name)
16
19
  end
17
20
 
18
21
  def lookup_model(table_name, scoped_class = '')
19
- @schema_reflection.lookup_model(@connection, table_name, scoped_class)
22
+ source = defined?(@pool) ? @pool : @connection
23
+ @schema_reflection.lookup_model(source, table_name, scoped_class)
20
24
  end
21
25
  end
22
26
 
@@ -3,20 +3,20 @@
3
3
  module Torque
4
4
  module PostgreSQL
5
5
  module SchemaReflection
6
- def add_model_name(connection, table_name, model)
7
- cache(connection).add_model_name(connection, table_name, model)
6
+ def add_model_name(source, table_name, model)
7
+ cache(source).add_model_name(source, table_name, model)
8
8
  end
9
9
 
10
- def dependencies(connection, table_name)
11
- cache(connection).dependencies(connection, table_name)
10
+ def dependencies(source, table_name)
11
+ cache(source).dependencies(source, table_name)
12
12
  end
13
13
 
14
- def associations(connection, table_name)
15
- cache(connection).associations(connection, table_name)
14
+ def associations(source, table_name)
15
+ cache(source).associations(source, table_name)
16
16
  end
17
17
 
18
- def lookup_model(connection, table_name, scoped_class)
19
- cache(connection).lookup_model(table_name, scoped_class)
18
+ def lookup_model(source, table_name, scoped_class)
19
+ cache(source).lookup_model(table_name, scoped_class)
20
20
  end
21
21
  end
22
22
 
@@ -105,15 +105,15 @@ module Torque
105
105
  end
106
106
 
107
107
  # Get all the tables that the given one inherits from
108
- def dependencies(conn, table_name = conn)
109
- reload_inheritance_data!(conn == table_name ? connection : conn)
108
+ def dependencies(source, table_name = source)
109
+ reload_inheritance_data!(source == table_name ? connection : source)
110
110
  @inheritance_dependencies[table_name]
111
111
  end
112
112
 
113
113
  # Get the list of all tables that are associated (direct or indirect
114
114
  # inheritance) with the provided one
115
- def associations(conn, table_name = conn)
116
- reload_inheritance_data!(conn == table_name ? connection : conn)
115
+ def associations(source, table_name = source)
116
+ reload_inheritance_data!(source == table_name ? connection : source)
117
117
  @inheritance_associations[table_name]
118
118
  end
119
119
 
@@ -127,11 +127,15 @@ module Torque
127
127
 
128
128
  # Reload information about tables inheritance and dependencies, uses a
129
129
  # cache to not perform additional checks
130
- def reload_inheritance_data!(connection)
130
+ def reload_inheritance_data!(source)
131
131
  return if @inheritance_loaded
132
- @inheritance_dependencies = connection.inherited_tables
133
- @inheritance_associations = generate_associations
134
- @inheritance_loaded = true
132
+
133
+ method_name = Torque::PostgreSQL::AR720 ? :with_connection : :then
134
+ source.public_send(method_name) do |connection|
135
+ @inheritance_dependencies = connection.inherited_tables
136
+ @inheritance_associations = generate_associations
137
+ @inheritance_loaded = true
138
+ end
135
139
  end
136
140
 
137
141
  # Calculates the inverted dependency (association), where even indirect
@@ -141,11 +145,12 @@ module Torque
141
145
  end
142
146
 
143
147
  # Use this method to also load any irregular model name
144
- def prepare_data_sources(connection = nil)
145
- Torque::PostgreSQL::AR710 ? super : super()
148
+ method_name = Torque::PostgreSQL::AR720 ? :add_all : :prepare_data_sources
149
+ define_method(method_name) do |source = nil|
150
+ Torque::PostgreSQL::AR710 ? super(source) : super()
146
151
 
147
- sources = connection.present? ? tables_to_cache(connection) : @data_sources.keys
148
- @data_sources_model_names = prepare_irregular_models(sources)
152
+ data_sources = source.present? ? tables_to_cache(source) : @data_sources.keys
153
+ @data_sources_model_names = prepare_irregular_models(data_sources)
149
154
  end
150
155
 
151
156
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Torque
4
4
  module PostgreSQL
5
- VERSION = '3.3.3'
5
+ VERSION = '3.4.0'
6
6
  end
7
7
  end
@@ -1,16 +1,33 @@
1
1
  module Mocks
2
2
  module CacheQuery
3
- def get_last_executed_query(&block)
4
- conn = ActiveRecord::Base.connection
5
- conn.instance_variable_set(:@query_cache_enabled, true)
3
+ if Torque::PostgreSQL::AR720
4
+ def get_last_executed_query(&block)
5
+ cache = ActiveRecord::Base.connection.query_cache
6
+ cache.instance_variable_set(:@enabled, true)
6
7
 
7
- block.call
8
- result = conn.query_cache.keys.first
8
+ map = cache.instance_variable_get(:@map)
9
9
 
10
- conn.instance_variable_set(:@query_cache_enabled, false)
11
- conn.instance_variable_get(:@query_cache).delete(result)
10
+ block.call
11
+ result = map.keys.first
12
12
 
13
- result
13
+ cache.instance_variable_set(:@enabled, false)
14
+ map.delete(result)
15
+
16
+ result
17
+ end
18
+ else
19
+ def get_last_executed_query(&block)
20
+ conn = ActiveRecord::Base.connection
21
+ conn.instance_variable_set(:@query_cache_enabled, true)
22
+
23
+ block.call
24
+ result = conn.query_cache.keys.first
25
+
26
+ conn.instance_variable_set(:@query_cache_enabled, false)
27
+ conn.instance_variable_get(:@query_cache).delete(result)
28
+
29
+ result
30
+ end
14
31
  end
15
32
  end
16
33
  end
data/spec/spec_helper.rb CHANGED
@@ -40,7 +40,7 @@ RSpec.configure do |config|
40
40
  # Handles acton before rspec initialize
41
41
  config.before(:suite) do
42
42
  Torque::PostgreSQL.config.schemas.whitelist << 'internal'
43
- ActiveSupport::Deprecation.silenced = true
43
+ ActiveSupport::Deprecation.try(:silenced=, true)
44
44
  DatabaseCleaner.clean_with(:truncation)
45
45
  end
46
46
 
@@ -672,7 +672,7 @@ RSpec.describe 'AuxiliaryStatement' do
672
672
  result << ' SELECT COUNT(*) FROM "users"'
673
673
  result << ' INNER JOIN "comments" ON "comments"."user_id" = "users"."id"'
674
674
 
675
- query = get_last_executed_query{ subject.with(:comments).count }
675
+ query = get_last_executed_query { subject.with(:comments).count }
676
676
  expect(query).to eql(result)
677
677
  end
678
678
 
@@ -687,7 +687,7 @@ RSpec.describe 'AuxiliaryStatement' do
687
687
  result << ' SELECT SUM("comments"."value") FROM "users"'
688
688
  result << ' INNER JOIN "comments" ON "comments"."user_id" = "users"."id"'
689
689
 
690
- query = get_last_executed_query{ subject.with(:comments).sum(comments: :value) }
690
+ query = get_last_executed_query { subject.with(:comments).sum(comments: :value) }
691
691
  expect(query).to eql(result)
692
692
  end
693
693
 
@@ -5,6 +5,8 @@ RSpec.describe 'BelongsToMany' do
5
5
  let(:model) { Video }
6
6
  let(:builder) { Torque::PostgreSQL::Associations::Builder::BelongsToMany }
7
7
  let(:reflection) { Torque::PostgreSQL::Reflection::BelongsToManyReflection }
8
+ let(:key) { Torque::PostgreSQL::AR720 ? :tests : 'tests' }
9
+
8
10
  after { model._reflections = {} }
9
11
 
10
12
  it 'has the builder method' do
@@ -24,7 +26,7 @@ RSpec.describe 'BelongsToMany' do
24
26
  it 'allows setting up foreign key and primary_key as symbol' do
25
27
  model.belongs_to_many(:tests, foreign_key: :test_ids, primary_key: :test_id)
26
28
 
27
- reflection = model._reflections['tests']
29
+ reflection = model._reflections[key]
28
30
  expect(reflection.foreign_key).to be_eql('test_ids')
29
31
  expect(reflection.active_record_primary_key).to be_eql('test_id')
30
32
  end
@@ -33,6 +35,7 @@ RSpec.describe 'BelongsToMany' do
33
35
  context 'on association' do
34
36
  let(:other) { Tag }
35
37
  let(:initial) { FactoryBot.create(:tag) }
38
+ let(:key) { Torque::PostgreSQL::AR720 ? :tags : 'tags' }
36
39
 
37
40
  before { Video.belongs_to_many(:tags) }
38
41
  subject { Video.create(title: 'A') }
@@ -44,11 +47,11 @@ RSpec.describe 'BelongsToMany' do
44
47
 
45
48
  it 'has the method' do
46
49
  expect(subject).to respond_to(:tags)
47
- expect(subject._reflections).to include('tags')
50
+ expect(subject._reflections).to include(key)
48
51
  end
49
52
 
50
53
  it 'has correct foreign key' do
51
- item = subject._reflections['tags']
54
+ item = subject._reflections[key]
52
55
  expect(item.foreign_key).to be_eql('tag_ids')
53
56
  end
54
57
 
@@ -43,8 +43,16 @@ RSpec.describe 'Enum' do
43
43
  end
44
44
 
45
45
  context 'on schema' do
46
+ let(:source) do
47
+ if Torque::PostgreSQL::AR720
48
+ ActiveRecord::Base.connection_pool
49
+ else
50
+ ActiveRecord::Base.connection
51
+ end
52
+ end
53
+
46
54
  let(:dump_result) do
47
- ActiveRecord::SchemaDumper.dump(connection, (dump_result = StringIO.new))
55
+ ActiveRecord::SchemaDumper.dump(source, (dump_result = StringIO.new))
48
56
  dump_result.string
49
57
  end
50
58
 
@@ -11,6 +11,7 @@ RSpec.describe 'HasMany' do
11
11
 
12
12
  context 'on original' do
13
13
  let(:other) { Text }
14
+ let(:key) { Torque::PostgreSQL::AR720 ? :texts : 'texts' }
14
15
 
15
16
  before { User.has_many :texts }
16
17
  subject { User.create(name: 'User 1') }
@@ -18,11 +19,11 @@ RSpec.describe 'HasMany' do
18
19
 
19
20
  it 'has the method' do
20
21
  expect(subject).to respond_to(:texts)
21
- expect(subject._reflections).to include('texts')
22
+ expect(subject._reflections).to include(key)
22
23
  end
23
24
 
24
25
  it 'has correct foreign key' do
25
- item = subject._reflections['texts']
26
+ item = subject._reflections[key]
26
27
  expect(item.foreign_key).to be_eql('user_id')
27
28
  end
28
29
 
@@ -246,6 +247,7 @@ RSpec.describe 'HasMany' do
246
247
 
247
248
  context 'on array' do
248
249
  let(:other) { Video }
250
+ let(:key) { Torque::PostgreSQL::AR720 ? :videos : 'videos' }
249
251
 
250
252
  before { Tag.has_many :videos, array: true }
251
253
  subject { Tag.create(name: 'A') }
@@ -253,11 +255,11 @@ RSpec.describe 'HasMany' do
253
255
 
254
256
  it 'has the method' do
255
257
  expect(subject).to respond_to(:videos)
256
- expect(subject._reflections).to include('videos')
258
+ expect(subject._reflections).to include(key)
257
259
  end
258
260
 
259
261
  it 'has correct foreign key' do
260
- item = subject._reflections['videos']
262
+ item = subject._reflections[key]
261
263
  expect(item.foreign_key).to be_eql('tag_ids')
262
264
  end
263
265
 
@@ -1,8 +1,15 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.describe 'Interval' do
4
- let(:connection) { ActiveRecord::Base.connection }
5
4
  let(:table_definition) { ActiveRecord::ConnectionAdapters::PostgreSQL::TableDefinition }
5
+ let(:connection) { ActiveRecord::Base.connection }
6
+ let(:source) do
7
+ if Torque::PostgreSQL::AR720
8
+ ActiveRecord::Base.connection_pool
9
+ else
10
+ ActiveRecord::Base.connection
11
+ end
12
+ end
6
13
 
7
14
  context 'on settings' do
8
15
  it 'must be set to ISO 8601' do
@@ -27,7 +34,7 @@ RSpec.describe 'Interval' do
27
34
  context 'on schema' do
28
35
  it 'can be used on tables too' do
29
36
  dump_io = StringIO.new
30
- ActiveRecord::SchemaDumper.dump(connection, dump_io)
37
+ ActiveRecord::SchemaDumper.dump(source, dump_io)
31
38
  expect(dump_io.string).to match /t\.interval +"duration"/
32
39
  end
33
40
  end
@@ -2,6 +2,13 @@ require 'spec_helper'
2
2
 
3
3
  RSpec.describe 'Schema' do
4
4
  let(:connection) { ActiveRecord::Base.connection }
5
+ let(:source) do
6
+ if Torque::PostgreSQL::AR720
7
+ ActiveRecord::Base.connection_pool
8
+ else
9
+ ActiveRecord::Base.connection
10
+ end
11
+ end
5
12
 
6
13
  before do
7
14
  connection.instance_variable_set(:@schemas_blacklist, nil)
@@ -64,7 +71,7 @@ RSpec.describe 'Schema' do
64
71
 
65
72
  context 'on schema' do
66
73
  let(:dump_result) do
67
- ActiveRecord::SchemaDumper.dump(connection, (dump_result = StringIO.new))
74
+ ActiveRecord::SchemaDumper.dump(source, (dump_result = StringIO.new))
68
75
  dump_result.string
69
76
  end
70
77
 
@@ -73,8 +73,16 @@ RSpec.describe 'TableInheritance' do
73
73
  end
74
74
 
75
75
  context 'on schema' do
76
+ let(:source) do
77
+ if Torque::PostgreSQL::AR720
78
+ ActiveRecord::Base.connection_pool
79
+ else
80
+ ActiveRecord::Base.connection
81
+ end
82
+ end
83
+
76
84
  let(:dump_result) do
77
- ActiveRecord::SchemaDumper.dump(connection, (dump_result = StringIO.new))
85
+ ActiveRecord::SchemaDumper.dump(source, (dump_result = StringIO.new))
78
86
  dump_result.string
79
87
  end
80
88
 
@@ -105,9 +113,12 @@ RSpec.describe 'TableInheritance' do
105
113
 
106
114
  context 'on schema cache' do
107
115
  let(:schema_cache) { ActiveRecord::Base.connection.schema_cache }
108
- let(:schema_cache_connection) { schema_cache.instance_variable_get(:@connection) }
109
116
  let(:schema_cache_reflection) { schema_cache.instance_variable_get(:@schema_reflection) }
110
- let(:new_schema_cache) { schema_cache_reflection.send(:cache, schema_cache_connection) }
117
+ let(:new_schema_cache) { schema_cache_reflection.send(:cache, schema_cache_source) }
118
+
119
+ let(:schema_cache_source) do
120
+ schema_cache.instance_variable_get(Torque::PostgreSQL::AR720 ? :@pool : :@connection)
121
+ end
111
122
 
112
123
  subject { Torque::PostgreSQL::AR710 ? new_schema_cache : schema_cache }
113
124
 
@@ -137,7 +148,8 @@ RSpec.describe 'TableInheritance' do
137
148
  end
138
149
 
139
150
  context 'on looking up models' do
140
- let(:prepare_arguments) { Torque::PostgreSQL::AR710 ? [schema_cache_connection] : nil }
151
+ let(:prepare_arguments) { Torque::PostgreSQL::AR710 ? [schema_cache_source] : nil }
152
+ let(:prepare_method) { Torque::PostgreSQL::AR720 ? :add_all : :prepare_data_sources }
141
153
 
142
154
  after(:all) do
143
155
  schema_cache = ActiveRecord::Base.connection.schema_cache
@@ -150,7 +162,7 @@ RSpec.describe 'TableInheritance' do
150
162
  'public.posts' => 'ActivityPost',
151
163
  })
152
164
 
153
- subject.send(:prepare_data_sources, *prepare_arguments)
165
+ subject.send(prepare_method, *prepare_arguments)
154
166
  list = subject.instance_variable_get(:@data_sources_model_names)
155
167
  expect(list).to have_key('public.posts')
156
168
  expect(list['public.posts']).to eql(ActivityPost)
@@ -161,7 +173,7 @@ RSpec.describe 'TableInheritance' do
161
173
  'products' => 'Product',
162
174
  })
163
175
 
164
- subject.send(:prepare_data_sources, *prepare_arguments)
176
+ subject.send(prepare_method, *prepare_arguments)
165
177
  list = subject.instance_variable_get(:@data_sources_model_names)
166
178
  expect(list).to_not have_key('products')
167
179
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: torque-postgresql
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.3
4
+ version: 3.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carlos Silva
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-21 00:00:00.000000000 Z
11
+ date: 2024-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -290,7 +290,7 @@ metadata:
290
290
  source_code_uri: https://github.com/crashtech/torque-postgresql
291
291
  bug_tracker_uri: https://github.com/crashtech/torque-postgresql/issues
292
292
  changelog_uri: https://github.com/crashtech/torque-postgresql/releases
293
- post_install_message:
293
+ post_install_message:
294
294
  rdoc_options:
295
295
  - "--title"
296
296
  - Torque PostgreSQL
@@ -307,8 +307,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
307
307
  - !ruby/object:Gem::Version
308
308
  version: 1.8.11
309
309
  requirements: []
310
- rubygems_version: 3.2.15
311
- signing_key:
310
+ rubygems_version: 3.4.10
311
+ signing_key:
312
312
  specification_version: 4
313
313
  summary: ActiveRecord extension to access PostgreSQL advanced resources
314
314
  test_files: