torque-postgresql 2.0.0 → 2.0.5
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.
- checksums.yaml +4 -4
- data/lib/torque/postgresql.rb +0 -1
- data/lib/torque/postgresql/adapter.rb +7 -0
- data/lib/torque/postgresql/adapter/database_statements.rb +2 -0
- data/lib/torque/postgresql/adapter/oid.rb +3 -1
- data/lib/torque/postgresql/adapter/oid/box.rb +2 -0
- data/lib/torque/postgresql/adapter/oid/circle.rb +2 -0
- data/lib/torque/postgresql/adapter/oid/enum.rb +2 -0
- data/lib/torque/postgresql/adapter/oid/enum_set.rb +2 -0
- data/lib/torque/postgresql/adapter/oid/interval.rb +2 -0
- data/lib/torque/postgresql/adapter/oid/line.rb +2 -0
- data/lib/torque/postgresql/adapter/oid/range.rb +2 -0
- data/lib/torque/postgresql/adapter/oid/segment.rb +2 -0
- data/lib/torque/postgresql/adapter/quoting.rb +2 -0
- data/lib/torque/postgresql/adapter/schema_creation.rb +8 -1
- data/lib/torque/postgresql/adapter/schema_definitions.rb +2 -0
- data/lib/torque/postgresql/adapter/schema_dumper.rb +23 -18
- data/lib/torque/postgresql/adapter/schema_statements.rb +2 -0
- data/lib/torque/postgresql/arel/infix_operation.rb +5 -1
- data/lib/torque/postgresql/arel/join_source.rb +2 -0
- data/lib/torque/postgresql/arel/nodes.rb +2 -0
- data/lib/torque/postgresql/arel/operations.rb +2 -0
- data/lib/torque/postgresql/arel/select_manager.rb +2 -0
- data/lib/torque/postgresql/arel/visitors.rb +6 -3
- data/lib/torque/postgresql/associations/association.rb +9 -1
- data/lib/torque/postgresql/associations/association_scope.rb +2 -0
- data/lib/torque/postgresql/associations/belongs_to_many_association.rb +17 -10
- data/lib/torque/postgresql/associations/builder/belongs_to_many.rb +2 -0
- data/lib/torque/postgresql/associations/builder/has_many.rb +2 -0
- data/lib/torque/postgresql/associations/preloader/association.rb +30 -1
- data/lib/torque/postgresql/attributes/builder.rb +3 -1
- data/lib/torque/postgresql/attributes/builder/enum.rb +5 -3
- data/lib/torque/postgresql/attributes/builder/period.rb +6 -4
- data/lib/torque/postgresql/attributes/enum.rb +5 -10
- data/lib/torque/postgresql/attributes/enum_set.rb +2 -0
- data/lib/torque/postgresql/attributes/lazy.rb +3 -1
- data/lib/torque/postgresql/attributes/period.rb +2 -0
- data/lib/torque/postgresql/auxiliary_statement.rb +2 -0
- data/lib/torque/postgresql/auxiliary_statement/settings.rb +2 -0
- data/lib/torque/postgresql/base.rb +2 -0
- data/lib/torque/postgresql/coder.rb +5 -3
- data/lib/torque/postgresql/collector.rb +2 -0
- data/lib/torque/postgresql/config.rb +5 -0
- data/lib/torque/postgresql/geometry_builder.rb +2 -0
- data/lib/torque/postgresql/i18n.rb +2 -0
- data/lib/torque/postgresql/inheritance.rb +2 -0
- data/lib/torque/postgresql/migration/command_recorder.rb +2 -0
- data/lib/torque/postgresql/railtie.rb +2 -0
- data/lib/torque/postgresql/reflection.rb +2 -0
- data/lib/torque/postgresql/reflection/abstract_reflection.rb +13 -5
- data/lib/torque/postgresql/reflection/association_reflection.rb +2 -0
- data/lib/torque/postgresql/reflection/belongs_to_many_reflection.rb +18 -4
- data/lib/torque/postgresql/reflection/has_many_reflection.rb +2 -0
- data/lib/torque/postgresql/reflection/runtime_reflection.rb +2 -0
- data/lib/torque/postgresql/reflection/through_reflection.rb +2 -0
- data/lib/torque/postgresql/relation.rb +15 -11
- data/lib/torque/postgresql/relation/auxiliary_statement.rb +6 -1
- data/lib/torque/postgresql/relation/distinct_on.rb +2 -0
- data/lib/torque/postgresql/relation/inheritance.rb +2 -0
- data/lib/torque/postgresql/relation/merger.rb +2 -0
- data/lib/torque/postgresql/schema_cache.rb +2 -0
- data/lib/torque/postgresql/version.rb +3 -1
- data/spec/schema.rb +2 -2
- data/spec/tests/arel_spec.rb +3 -1
- data/spec/tests/belongs_to_many_spec.rb +6 -0
- data/spec/tests/enum_set_spec.rb +1 -1
- data/spec/tests/enum_spec.rb +7 -0
- data/spec/tests/has_many_spec.rb +11 -1
- data/spec/tests/table_inheritance_spec.rb +14 -1
- metadata +9 -10
- data/lib/torque/postgresql/autosave_association.rb +0 -39
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Torque
|
2
4
|
module PostgreSQL
|
3
5
|
module Relation
|
@@ -34,7 +36,10 @@ module Torque
|
|
34
36
|
# attributes as well
|
35
37
|
def bound_attributes
|
36
38
|
visitor = ::Arel::Visitors::PostgreSQL.new(ActiveRecord::Base.connection)
|
37
|
-
visitor.accept(self.arel.ast, ::Arel::Collectors::
|
39
|
+
visitor.accept(self.arel.ast, ::Arel::Collectors::Composite.new(
|
40
|
+
::Arel::Collectors::SQLString.new,
|
41
|
+
::Arel::Collectors::Bind.new,
|
42
|
+
)).value.last
|
38
43
|
end
|
39
44
|
|
40
45
|
private
|
data/spec/schema.rb
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
# It's strongly recommended that you check this file into your version control system.
|
12
12
|
|
13
13
|
begin
|
14
|
-
version =
|
14
|
+
version = 62
|
15
15
|
|
16
16
|
raise SystemExit if ActiveRecord::Migrator.current_version == version
|
17
17
|
ActiveRecord::Schema.define(version: version) do
|
@@ -83,7 +83,7 @@ begin
|
|
83
83
|
create_table "courses", force: :cascade do |t|
|
84
84
|
t.string "title", null: false
|
85
85
|
t.interval "duration"
|
86
|
-
t.enum "types", subtype: :types, array: true
|
86
|
+
t.enum "types", subtype: :types, array: true
|
87
87
|
t.datetime "created_at", null: false
|
88
88
|
t.datetime "updated_at", null: false
|
89
89
|
end
|
data/spec/tests/arel_spec.rb
CHANGED
@@ -25,7 +25,9 @@ RSpec.describe 'Arel' do
|
|
25
25
|
klass_name = operator.to_s.camelize
|
26
26
|
|
27
27
|
context "##{operator}" do
|
28
|
-
let(:instance)
|
28
|
+
let(:instance) do
|
29
|
+
attribute.public_send(operator, value.is_a?(Array) ? ::Arel.array(value) : value)
|
30
|
+
end
|
29
31
|
|
30
32
|
context 'for attribute' do
|
31
33
|
let(:klass) { ::Arel::Nodes.const_get(klass_name) }
|
@@ -35,6 +35,11 @@ RSpec.describe 'BelongsToMany' do
|
|
35
35
|
expect(subject._reflections).to include('tags')
|
36
36
|
end
|
37
37
|
|
38
|
+
it 'has correct foreign key' do
|
39
|
+
item = subject._reflections['tags']
|
40
|
+
expect(item.foreign_key).to be_eql('tag_ids')
|
41
|
+
end
|
42
|
+
|
38
43
|
it 'loads associated records' do
|
39
44
|
subject.update(tag_ids: [initial.id])
|
40
45
|
expect(subject.tags.to_sql).to be_eql(<<-SQL.squish)
|
@@ -116,6 +121,7 @@ RSpec.describe 'BelongsToMany' do
|
|
116
121
|
|
117
122
|
subject.tags.concat(other.new(name: 'Test'))
|
118
123
|
subject.tags.reload
|
124
|
+
|
119
125
|
expect(subject.tags.size).to be_eql(2)
|
120
126
|
expect(subject.tag_ids.size).to be_eql(2)
|
121
127
|
expect(subject.tags.last.name).to be_eql('Test')
|
data/spec/tests/enum_set_spec.rb
CHANGED
@@ -48,7 +48,7 @@ RSpec.describe 'Enum' do
|
|
48
48
|
expect(dump_io.string).to match checker
|
49
49
|
end
|
50
50
|
|
51
|
-
|
51
|
+
xit 'can have a default value as an array of symbols' do
|
52
52
|
dump_io = StringIO.new
|
53
53
|
checker = /t\.enum +"types", +default: \[:A, :B\], +array: true, +subtype: :types/
|
54
54
|
ActiveRecord::SchemaDumper.dump(connection, dump_io)
|
data/spec/tests/enum_spec.rb
CHANGED
@@ -124,6 +124,13 @@ RSpec.describe 'Enum' do
|
|
124
124
|
expect(dump_io.string).to match /create_enum \"content_status\", \[/
|
125
125
|
end
|
126
126
|
|
127
|
+
it 'sorts the enum entries to better consistency' do
|
128
|
+
dump_io = StringIO.new
|
129
|
+
ActiveRecord::SchemaDumper.dump(connection, dump_io)
|
130
|
+
items = dump_io.string.scan(/create_enum "(\w+)"/).flatten
|
131
|
+
expect(items).to be_eql(items.sort)
|
132
|
+
end
|
133
|
+
|
127
134
|
it 'do not dump when has none' do
|
128
135
|
connection.drop_type(:content_status, force: :cascade)
|
129
136
|
|
data/spec/tests/has_many_spec.rb
CHANGED
@@ -5,7 +5,7 @@ RSpec.describe 'HasMany' do
|
|
5
5
|
let(:builder) { ActiveRecord::Associations::Builder::HasMany }
|
6
6
|
|
7
7
|
it 'adds the array option' do
|
8
|
-
expect(builder.send(:valid_options,
|
8
|
+
expect(builder.send(:valid_options, {})).to include(:array)
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
@@ -21,6 +21,11 @@ RSpec.describe 'HasMany' do
|
|
21
21
|
expect(subject._reflections).to include('texts')
|
22
22
|
end
|
23
23
|
|
24
|
+
it 'has correct foreign key' do
|
25
|
+
item = subject._reflections['texts']
|
26
|
+
expect(item.foreign_key).to be_eql('user_id')
|
27
|
+
end
|
28
|
+
|
24
29
|
it 'loads associated records' do
|
25
30
|
expect(subject.texts.to_sql).to match(Regexp.new(<<-SQL.squish))
|
26
31
|
SELECT "texts"\\.\\* FROM "texts" WHERE \\(?"texts"\\."user_id" = #{subject.id}\\)?
|
@@ -210,6 +215,11 @@ RSpec.describe 'HasMany' do
|
|
210
215
|
expect(subject._reflections).to include('videos')
|
211
216
|
end
|
212
217
|
|
218
|
+
it 'has correct foreign key' do
|
219
|
+
item = subject._reflections['videos']
|
220
|
+
expect(item.foreign_key).to be_eql('tag_ids')
|
221
|
+
end
|
222
|
+
|
213
223
|
it 'loads associated records' do
|
214
224
|
expect(subject.videos.to_sql).to match(Regexp.new(<<-SQL.squish))
|
215
225
|
SELECT "videos"\\.\\* FROM "videos"
|
@@ -66,7 +66,7 @@ RSpec.describe 'TableInheritance' do
|
|
66
66
|
|
67
67
|
it 'allows empty-body create table operation' do
|
68
68
|
sql = connection.create_table(:activity_posts, inherits: :activities)
|
69
|
-
result =
|
69
|
+
result = "CREATE TABLE \"activity_posts\" ()"
|
70
70
|
result << ' INHERITS ( "activities" )'
|
71
71
|
expect(sql).to eql(result)
|
72
72
|
end
|
@@ -231,6 +231,19 @@ RSpec.describe 'TableInheritance' do
|
|
231
231
|
expect(child2.table_name).to eql('activity_books')
|
232
232
|
expect(other.table_name).to eql('authors')
|
233
233
|
end
|
234
|
+
|
235
|
+
it 'respects the table name prefix and sufix defined on parent module' do
|
236
|
+
mod = Object.const_set('Private', Module.new)
|
237
|
+
mod.define_singleton_method(:table_name_prefix) { 'private.' }
|
238
|
+
mod.define_singleton_method(:table_name_suffix) { '_bundle' }
|
239
|
+
result = 'private.activity_post_others_bundle'
|
240
|
+
|
241
|
+
klass = mod.const_set('Other', Class.new(ActivityPost))
|
242
|
+
allow(klass).to receive(:module_parent).and_return(child)
|
243
|
+
allow(klass).to receive(:module_parents).and_return([mod])
|
244
|
+
allow(klass).to receive(:physically_inherited?).and_return(true)
|
245
|
+
expect(klass.send(:compute_table_name)).to be_eql(result)
|
246
|
+
end
|
234
247
|
end
|
235
248
|
|
236
249
|
context 'on relation' do
|
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: 2.0.
|
4
|
+
version: 2.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carlos Silva
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -211,7 +211,6 @@ files:
|
|
211
211
|
- lib/torque/postgresql/attributes/enum_set.rb
|
212
212
|
- lib/torque/postgresql/attributes/lazy.rb
|
213
213
|
- lib/torque/postgresql/attributes/period.rb
|
214
|
-
- lib/torque/postgresql/autosave_association.rb
|
215
214
|
- lib/torque/postgresql/auxiliary_statement.rb
|
216
215
|
- lib/torque/postgresql/auxiliary_statement/settings.rb
|
217
216
|
- lib/torque/postgresql/base.rb
|
@@ -303,7 +302,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
303
302
|
- !ruby/object:Gem::Version
|
304
303
|
version: 1.8.11
|
305
304
|
requirements: []
|
306
|
-
rubygems_version: 3.1.
|
305
|
+
rubygems_version: 3.1.4
|
307
306
|
signing_key:
|
308
307
|
specification_version: 4
|
309
308
|
summary: ActiveRecord extension to access PostgreSQL advanced resources
|
@@ -333,11 +332,10 @@ test_files:
|
|
333
332
|
- spec/factories/videos.rb
|
334
333
|
- spec/tests/geometric_builder_spec.rb
|
335
334
|
- spec/tests/range_spec.rb
|
336
|
-
- spec/tests/auxiliary_statement_spec.rb
|
337
|
-
- spec/tests/belongs_to_many_spec.rb
|
338
|
-
- spec/tests/has_many_spec.rb
|
339
|
-
- spec/tests/period_spec.rb
|
340
335
|
- spec/tests/table_inheritance_spec.rb
|
336
|
+
- spec/tests/enum_spec.rb
|
337
|
+
- spec/tests/auxiliary_statement_spec.rb
|
338
|
+
- spec/tests/enum_set_spec.rb
|
341
339
|
- spec/tests/coder_spec.rb
|
342
340
|
- spec/tests/collector_spec.rb
|
343
341
|
- spec/tests/distinct_on_spec.rb
|
@@ -345,9 +343,10 @@ test_files:
|
|
345
343
|
- spec/tests/lazy_spec.rb
|
346
344
|
- spec/tests/quoting_spec.rb
|
347
345
|
- spec/tests/relation_spec.rb
|
346
|
+
- spec/tests/belongs_to_many_spec.rb
|
347
|
+
- spec/tests/period_spec.rb
|
348
348
|
- spec/tests/arel_spec.rb
|
349
|
-
- spec/tests/
|
350
|
-
- spec/tests/enum_spec.rb
|
349
|
+
- spec/tests/has_many_spec.rb
|
351
350
|
- spec/mocks/cache_query.rb
|
352
351
|
- spec/mocks/create_table.rb
|
353
352
|
- spec/en.yml
|
@@ -1,39 +0,0 @@
|
|
1
|
-
module Torque
|
2
|
-
module PostgreSQL
|
3
|
-
module AutosaveAssociation
|
4
|
-
module ClassMethods
|
5
|
-
def add_autosave_association_callbacks(reflection)
|
6
|
-
return super unless reflection.macro.eql?(:belongs_to_many)
|
7
|
-
|
8
|
-
save_method = :"autosave_associated_records_for_#{reflection.name}"
|
9
|
-
define_non_cyclic_method(save_method) { save_belongs_to_many_array(reflection) }
|
10
|
-
|
11
|
-
before_save(:before_save_collection_association)
|
12
|
-
after_save(:after_save_collection_association) if ::ActiveRecord::Base
|
13
|
-
.instance_methods.include?(:after_save_collection_association)
|
14
|
-
|
15
|
-
before_create(save_method)
|
16
|
-
before_update(save_method)
|
17
|
-
|
18
|
-
define_autosave_validation_callbacks(reflection)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def save_belongs_to_many_array(reflection)
|
23
|
-
save_collection_association(reflection)
|
24
|
-
|
25
|
-
association = association_instance_get(reflection.name)
|
26
|
-
return unless association
|
27
|
-
|
28
|
-
klass_fk = reflection.foreign_key
|
29
|
-
acpk = reflection.active_record_primary_key
|
30
|
-
|
31
|
-
records = association.target.each_with_object(klass_fk)
|
32
|
-
write_attribute(acpk, records.map(&:read_attribute).compact)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
::ActiveRecord::Base.singleton_class.prepend(AutosaveAssociation::ClassMethods)
|
37
|
-
::ActiveRecord::Base.include(AutosaveAssociation)
|
38
|
-
end
|
39
|
-
end
|