torque-postgresql 2.1.2 → 2.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/torque/postgresql/adapter/database_statements.rb +2 -0
- data/lib/torque/postgresql/adapter/quoting.rb +8 -5
- data/lib/torque/postgresql/adapter/schema_statements.rb +5 -1
- data/lib/torque/postgresql/adapter.rb +20 -4
- data/lib/torque/postgresql/associations/preloader/association.rb +2 -2
- data/lib/torque/postgresql/attributes/builder/period.rb +2 -6
- data/lib/torque/postgresql/base.rb +1 -1
- data/lib/torque/postgresql/config.rb +6 -0
- data/lib/torque/postgresql/inheritance.rb +1 -1
- data/lib/torque/postgresql/reflection/belongs_to_many_reflection.rb +4 -2
- data/lib/torque/postgresql/relation/inheritance.rb +9 -14
- data/lib/torque/postgresql/relation.rb +1 -1
- data/lib/torque/postgresql/version.rb +1 -1
- data/lib/torque/range.rb +0 -2
- data/spec/models/question.rb +3 -0
- data/spec/models/question_select.rb +2 -0
- data/spec/schema.rb +12 -1
- data/spec/tests/arel_spec.rb +43 -0
- data/spec/tests/period_spec.rb +9 -0
- data/spec/tests/range_spec.rb +1 -1
- data/spec/tests/table_inheritance_spec.rb +30 -21
- metadata +11 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 573548a4177e130f445da5816cf833bb21508a2612c71fd3f8fc6a78c7ce04fc
|
4
|
+
data.tar.gz: 509acb45a89a55c30a626117c61a5fc23b9a635f041b1ff6549fed4d221a7571
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2267add7a9e17636f0f8ee274d5263d065390998e34b513bede849b7f39292a9742432a6ac41a27930c6cbb49216adccdfb09322497177887267452513494c1f
|
7
|
+
data.tar.gz: 5c3c5174170a4f3eb988f6c1c62c56465da91371a3f3d216ba85ba02e1721dce1c99f93e1964bd7f8b9ebd600beed512d4a713349e2435fd686c8bdaa2f0d6d3
|
@@ -6,6 +6,8 @@ module Torque
|
|
6
6
|
module Quoting
|
7
7
|
|
8
8
|
Name = ActiveRecord::ConnectionAdapters::PostgreSQL::Name
|
9
|
+
Column = ActiveRecord::ConnectionAdapters::PostgreSQL::Column
|
10
|
+
ColumnDefinition = ActiveRecord::ConnectionAdapters::ColumnDefinition
|
9
11
|
|
10
12
|
# Quotes type names for use in SQL queries.
|
11
13
|
def quote_type_name(string, schema = nil)
|
@@ -20,11 +22,12 @@ module Torque
|
|
20
22
|
end
|
21
23
|
|
22
24
|
def quote_default_expression(value, column)
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
return super unless value.class <= Array &&
|
26
|
+
((column.is_a?(ColumnDefinition) && column.dig(:options, :array)) ||
|
27
|
+
(column.is_a?(Column) && column.array?))
|
28
|
+
|
29
|
+
type = column.is_a?(Column) ? column.sql_type_metadata.sql_type : column.sql_type
|
30
|
+
quote(value) + '::' + type
|
28
31
|
end
|
29
32
|
|
30
33
|
private
|
@@ -70,7 +70,11 @@ module Torque
|
|
70
70
|
|
71
71
|
# Returns all values that an enum type can have.
|
72
72
|
def enum_values(name)
|
73
|
-
select_values(
|
73
|
+
select_values(<<-SQL.squish, 'SCHEMA')
|
74
|
+
SELECT enumlabel FROM pg_enum
|
75
|
+
WHERE enumtypid = #{quote(name)}::regtype::oid
|
76
|
+
ORDER BY enumsortorder
|
77
|
+
SQL
|
74
78
|
end
|
75
79
|
|
76
80
|
# Rewrite the method that creates tables to easily accept extra options
|
@@ -15,7 +15,14 @@ module Torque
|
|
15
15
|
include DatabaseStatements
|
16
16
|
include SchemaStatements
|
17
17
|
|
18
|
-
|
18
|
+
# :nodoc:
|
19
|
+
class DeduplicatableArray < ::Array
|
20
|
+
def deduplicate
|
21
|
+
map { |value| -value }
|
22
|
+
end
|
23
|
+
|
24
|
+
alias :-@ :deduplicate
|
25
|
+
end
|
19
26
|
|
20
27
|
# Get the current PostgreSQL version as a Gem Version.
|
21
28
|
def version
|
@@ -29,19 +36,28 @@ module Torque
|
|
29
36
|
super.merge(options.extract!(:inherits))
|
30
37
|
end
|
31
38
|
|
32
|
-
# Allow filtered bulk insert by adding the where clause. This method is
|
33
|
-
# +InsertAll+, so it somewhat safe to override it
|
39
|
+
# Allow filtered bulk insert by adding the where clause. This method is
|
40
|
+
# only used by +InsertAll+, so it somewhat safe to override it
|
34
41
|
def build_insert_sql(insert)
|
35
42
|
super.tap do |sql|
|
36
43
|
if insert.update_duplicates? && insert.where_condition?
|
37
44
|
if insert.returning
|
38
|
-
sql.
|
45
|
+
sql.sub!(' RETURNING ', " WHERE #{insert.where} RETURNING ")
|
39
46
|
else
|
40
47
|
sql << " WHERE #{insert.where}"
|
41
48
|
end
|
42
49
|
end
|
43
50
|
end
|
44
51
|
end
|
52
|
+
|
53
|
+
# Extend the extract default value to support array
|
54
|
+
def extract_value_from_default(default)
|
55
|
+
return super unless Torque::PostgreSQL.config.use_extended_defaults
|
56
|
+
return super unless default&.match(/ARRAY\[(.*?)\](?:::"?([\w. ]+)"?(?:\[\])+)?$/)
|
57
|
+
|
58
|
+
arr = $1.split(/(?!\B\[[^\]]*), ?(?![^\[]*\]\B)/)
|
59
|
+
DeduplicatableArray.new(arr.map(&method(:extract_value_from_default)))
|
60
|
+
end
|
45
61
|
end
|
46
62
|
|
47
63
|
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.prepend Adapter
|
@@ -452,12 +452,8 @@ module Torque
|
|
452
452
|
def instance_current_on?
|
453
453
|
attr_value = threshold.present? ? method_names[:real] : attribute
|
454
454
|
default_value = default.inspect
|
455
|
-
|
456
|
-
|
457
|
-
"return #{default_value} if #{attr_value}.min.try(:infinite?)",
|
458
|
-
"return #{default_value} if #{attr_value}.max.try(:infinite?)",
|
459
|
-
"#{attr_value}.min < value && #{attr_value}.max > value",
|
460
|
-
].join("\n")
|
455
|
+
|
456
|
+
"#{attr_value}.nil? ? #{default_value} : #{attr_value}.include?(value)"
|
461
457
|
end
|
462
458
|
|
463
459
|
def instance_start
|
@@ -40,7 +40,7 @@ module Torque
|
|
40
40
|
|
41
41
|
pg_class = ::Arel::Table.new('pg_class')
|
42
42
|
source = ::Arel::Table.new(subclass.table_name, as: 'source')
|
43
|
-
quoted_id = ::Arel::Nodes::Quoted.new(
|
43
|
+
quoted_id = ::Arel::Nodes::Quoted.new(id)
|
44
44
|
|
45
45
|
query = ::Arel::SelectManager.new(pg_class)
|
46
46
|
query.join(source).on(pg_class['oid'].eq(source['tableoid']))
|
@@ -5,6 +5,7 @@ module Torque
|
|
5
5
|
include ActiveSupport::Configurable
|
6
6
|
|
7
7
|
# Stores a version check for compatibility purposes
|
8
|
+
AR604 = (ActiveRecord.gem_version >= Gem::Version.new('6.0.4'))
|
8
9
|
AR610 = (ActiveRecord.gem_version >= Gem::Version.new('6.1.0'))
|
9
10
|
|
10
11
|
# Use the same logger as the Active Record one
|
@@ -25,6 +26,11 @@ module Torque
|
|
25
26
|
# same configuration is set to true
|
26
27
|
config.eager_load = false
|
27
28
|
|
29
|
+
# This allows default values to have extended values like arrays and casted
|
30
|
+
# values. Extended defaults are still experimental, so enable and test it
|
31
|
+
# before using it in prod
|
32
|
+
config.use_extended_defaults = false
|
33
|
+
|
28
34
|
# Set a list of irregular model name when associated with table names
|
29
35
|
config.irregular_models = {}
|
30
36
|
def config.irregular_models=(hash)
|
@@ -146,7 +146,7 @@ module Torque
|
|
146
146
|
auto_cast = _auto_cast_attribute.to_s
|
147
147
|
record_class = _record_class_attribute.to_s
|
148
148
|
return super unless attributes.key?(record_class) &&
|
149
|
-
|
149
|
+
attributes.delete(auto_cast) && attributes[record_class] != table_name
|
150
150
|
|
151
151
|
klass = casted_dependents[attributes[record_class]]
|
152
152
|
raise_unable_to_cast(attributes[record_class]) if klass.nil?
|
@@ -56,8 +56,10 @@ module Torque
|
|
56
56
|
end
|
57
57
|
|
58
58
|
::ActiveRecord::Reflection.const_set(:BelongsToManyReflection, BelongsToManyReflection)
|
59
|
-
|
60
|
-
|
59
|
+
|
60
|
+
reflection_class = ::ActiveRecord::Reflection::AssociationReflection
|
61
|
+
reflection_class::VALID_AUTOMATIC_INVERSE_MACROS.push(:belongs_to_many) \
|
62
|
+
if reflection_class.const_defined?('VALID_AUTOMATIC_INVERSE_MACROS')
|
61
63
|
end
|
62
64
|
end
|
63
65
|
end
|
@@ -5,6 +5,8 @@ module Torque
|
|
5
5
|
module Relation
|
6
6
|
module Inheritance
|
7
7
|
|
8
|
+
# REGCLASS = ::Arel.sql('tableoid').cast('regclass')
|
9
|
+
|
8
10
|
# :nodoc:
|
9
11
|
def cast_records_value; get_value(:cast_records); end
|
10
12
|
# :nodoc:
|
@@ -44,14 +46,8 @@ module Torque
|
|
44
46
|
|
45
47
|
# Like #cast_records, but modifies relation in place
|
46
48
|
def cast_records!(*types, **options)
|
47
|
-
|
48
|
-
|
49
|
-
with!(record_class)
|
50
|
-
if options[:filter]
|
51
|
-
table = record_class.to_s.camelize.underscore
|
52
|
-
where!(table => { record_class => types.map(&:table_name) })
|
53
|
-
end
|
54
|
-
|
49
|
+
where!(regclass.cast(:varchar).in(types.map(&:table_name))) if options[:filter]
|
50
|
+
self.select_extra_values += [regclass.as(_record_class_attribute.to_s)]
|
55
51
|
self.cast_records_value = (types.present? ? types : model.casted_dependents.values)
|
56
52
|
self
|
57
53
|
end
|
@@ -109,13 +105,12 @@ module Torque
|
|
109
105
|
end
|
110
106
|
|
111
107
|
def build_auto_caster_marker(arel, types)
|
112
|
-
|
113
|
-
|
114
|
-
|
108
|
+
attribute = regclass.cast(:varchar).in(types.map(&:table_name))
|
109
|
+
attribute.as(self.class._auto_cast_attribute.to_s)
|
110
|
+
end
|
115
111
|
|
116
|
-
|
117
|
-
|
118
|
-
::Arel.sql(column.to_sql).as(auto_cast_attribute)
|
112
|
+
def regclass
|
113
|
+
arel_table['tableoid'].cast(:regclass)
|
119
114
|
end
|
120
115
|
|
121
116
|
end
|
@@ -117,7 +117,7 @@ module Torque
|
|
117
117
|
# because the type mapper may add new methods to the model. This happens
|
118
118
|
# for the given model Klass and its inheritances
|
119
119
|
module Initializer
|
120
|
-
def initialize(klass,
|
120
|
+
def initialize(klass, *, **)
|
121
121
|
super
|
122
122
|
|
123
123
|
klass.superclass.send(:relation) if klass.define_attribute_methods &&
|
data/lib/torque/range.rb
CHANGED
data/spec/schema.rb
CHANGED
@@ -11,13 +11,14 @@
|
|
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 = 73
|
15
15
|
|
16
16
|
raise SystemExit if ActiveRecord::Migrator.current_version == version
|
17
17
|
ActiveRecord::Schema.define(version: version) do
|
18
18
|
self.verbose = false
|
19
19
|
|
20
20
|
# These are extensions that must be enabled in order to support this database
|
21
|
+
enable_extension "pgcrypto"
|
21
22
|
enable_extension "plpgsql"
|
22
23
|
|
23
24
|
# These are user-defined types used on this database
|
@@ -125,6 +126,12 @@ begin
|
|
125
126
|
t.datetime "updated_at", null: false
|
126
127
|
end
|
127
128
|
|
129
|
+
create_table "questions", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
130
|
+
t.string "title"
|
131
|
+
t.datetime "created_at", null: false
|
132
|
+
t.datetime "updated_at", null: false
|
133
|
+
end
|
134
|
+
|
128
135
|
create_table "activity_books", force: :cascade, inherits: :activities do |t|
|
129
136
|
t.text "description"
|
130
137
|
t.string "url"
|
@@ -139,6 +146,10 @@ begin
|
|
139
146
|
|
140
147
|
create_table "activity_post_samples", force: :cascade, inherits: :activity_posts
|
141
148
|
|
149
|
+
create_table "question_selects", force: :cascade, inherits: :questions do |t|
|
150
|
+
t.string "options", array: true
|
151
|
+
end
|
152
|
+
|
142
153
|
# create_table "activity_blanks", force: :cascade, inherits: :activities
|
143
154
|
|
144
155
|
# create_table "activity_images", force: :cascade, inherits: [:activities, :images]
|
data/spec/tests/arel_spec.rb
CHANGED
@@ -48,6 +48,49 @@ RSpec.describe 'Arel' do
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
+
context 'on default value' do
|
52
|
+
let(:connection) { ActiveRecord::Base.connection }
|
53
|
+
|
54
|
+
before(:context) { Torque::PostgreSQL.config.use_extended_defaults = true }
|
55
|
+
after(:context) { Torque::PostgreSQL.config.use_extended_defaults = false }
|
56
|
+
after { Author.reset_column_information }
|
57
|
+
|
58
|
+
it 'does not break the change column default value method' do
|
59
|
+
connection.add_column(:authors, :enabled, :boolean)
|
60
|
+
expect { connection.change_column_default(:authors, :enabled, { from: nil, to: true }) }.not_to raise_error
|
61
|
+
expect(Author.columns_hash['enabled'].default).to eq('true')
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'does not break jsonb' do
|
65
|
+
expect { connection.add_column(:authors, :profile, :jsonb, default: []) }.not_to raise_error
|
66
|
+
expect(Author.columns_hash['profile'].default).to eq('[]')
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'works properly when column is an array' do
|
70
|
+
expect { connection.add_column(:authors, :tag_ids, :bigint, array: true, default: []) }.not_to raise_error
|
71
|
+
expect(Author.columns_hash['tag_ids'].default).to eq([])
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'works with an array with enum values' do
|
75
|
+
value = ['visitor', 'assistant']
|
76
|
+
expect { connection.add_column(:authors, :roles, :roles, array: true, default: value) }.not_to raise_error
|
77
|
+
expect(Author.columns_hash['roles'].default).to eq(value)
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'works with multi dimentional array' do
|
81
|
+
value = [['1', '2'], ['3', '4']]
|
82
|
+
expect { connection.add_column(:authors, :tag_ids, :string, array: true, default: value) }.not_to raise_error
|
83
|
+
expect(Author.columns_hash['tag_ids'].default).to eq(value)
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'works with change column default value' do
|
87
|
+
value = ['2', '3']
|
88
|
+
connection.add_column(:authors, :tag_ids, :string, array: true)
|
89
|
+
expect { connection.change_column_default(:authors, :tag_ids, { from: nil, to: value }) }.not_to raise_error
|
90
|
+
expect(Author.columns_hash['tag_ids'].default).to eq(value)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
51
94
|
context 'on cast' do
|
52
95
|
it 'provides an array method' do
|
53
96
|
sample1 = ::Arel.array(1, 2, 3, 4)
|
data/spec/tests/period_spec.rb
CHANGED
@@ -266,6 +266,15 @@ RSpec.describe 'Period' do
|
|
266
266
|
|
267
267
|
instance.period = 4.hour.from_now.utc..6.hour.from_now.utc
|
268
268
|
expect(instance).not_to be_current_period
|
269
|
+
|
270
|
+
instance.period = [nil, 4.hours.ago.utc]
|
271
|
+
expect(instance).not_to be_current_period
|
272
|
+
|
273
|
+
instance.period = [4.hours.from_now.utc, nil]
|
274
|
+
expect(instance).not_to be_current_period
|
275
|
+
|
276
|
+
instance.period = [nil, nil]
|
277
|
+
expect(instance).to be_current_period
|
269
278
|
end
|
270
279
|
|
271
280
|
it 'checks fro current based on a value' do
|
data/spec/tests/range_spec.rb
CHANGED
@@ -292,14 +292,12 @@ RSpec.describe 'TableInheritance' do
|
|
292
292
|
end
|
293
293
|
|
294
294
|
it 'adds all statements to load all the necessary records' do
|
295
|
-
result = '
|
296
|
-
result << ' SELECT "activities".*, "record_class"."_record_class", "i_0"."description"'
|
295
|
+
result = 'SELECT "activities".*, "activities"."tableoid"::regclass AS _record_class, "i_0"."description"'
|
297
296
|
result << ', COALESCE("i_0"."url", "i_1"."url", "i_2"."url") AS url, "i_0"."activated" AS activity_books__activated'
|
298
297
|
result << ', "i_1"."activated" AS activity_posts__activated, "i_2"."activated" AS activity_post_samples__activated'
|
299
298
|
result << ', COALESCE("i_1"."file", "i_2"."file") AS file, COALESCE("i_1"."post_id", "i_2"."post_id") AS post_id'
|
300
|
-
result << ", \"
|
299
|
+
result << ", \"activities\".\"tableoid\"::regclass::varchar IN ('activity_books', 'activity_posts', 'activity_post_samples') AS _auto_cast"
|
301
300
|
result << ' FROM "activities"'
|
302
|
-
result << ' INNER JOIN "record_class" ON "record_class"."oid" = "activities"."tableoid"'
|
303
301
|
result << ' LEFT OUTER JOIN "activity_books" "i_0" ON "activities"."id" = "i_0"."id"'
|
304
302
|
result << ' LEFT OUTER JOIN "activity_posts" "i_1" ON "activities"."id" = "i_1"."id"'
|
305
303
|
result << ' LEFT OUTER JOIN "activity_post_samples" "i_2" ON "activities"."id" = "i_2"."id"'
|
@@ -307,33 +305,27 @@ RSpec.describe 'TableInheritance' do
|
|
307
305
|
end
|
308
306
|
|
309
307
|
it 'can be have simplefied joins' do
|
310
|
-
result = '
|
311
|
-
result << ' SELECT "activities".*, "record_class"."_record_class"'
|
308
|
+
result = 'SELECT "activities".*, "activities"."tableoid"::regclass AS _record_class'
|
312
309
|
result << ', "i_0"."description", "i_0"."url", "i_0"."activated"'
|
313
|
-
result << ", \"
|
310
|
+
result << ", \"activities\".\"tableoid\"::regclass::varchar IN ('activity_books') AS _auto_cast"
|
314
311
|
result << ' FROM "activities"'
|
315
|
-
result << ' INNER JOIN "record_class" ON "record_class"."oid" = "activities"."tableoid"'
|
316
312
|
result << ' LEFT OUTER JOIN "activity_books" "i_0" ON "activities"."id" = "i_0"."id"'
|
317
313
|
expect(base.cast_records(child).all.to_sql).to eql(result)
|
318
314
|
end
|
319
315
|
|
320
316
|
it 'can be filtered by record type' do
|
321
|
-
result = '
|
322
|
-
result << ' SELECT "activities".*, "record_class"."_record_class"'
|
317
|
+
result = 'SELECT "activities".*, "activities"."tableoid"::regclass AS _record_class'
|
323
318
|
result << ', "i_0"."description", "i_0"."url", "i_0"."activated"'
|
324
|
-
result << ", \"
|
319
|
+
result << ", \"activities\".\"tableoid\"::regclass::varchar IN ('activity_books') AS _auto_cast"
|
325
320
|
result << ' FROM "activities"'
|
326
|
-
result << ' INNER JOIN "record_class" ON "record_class"."oid" = "activities"."tableoid"'
|
327
321
|
result << ' LEFT OUTER JOIN "activity_books" "i_0" ON "activities"."id" = "i_0"."id"'
|
328
|
-
result << " WHERE \"
|
322
|
+
result << " WHERE \"activities\".\"tableoid\"::regclass::varchar IN ('activity_books')"
|
329
323
|
expect(base.cast_records(child, filter: true).all.to_sql).to eql(result)
|
330
324
|
end
|
331
325
|
|
332
326
|
it 'works with count and does not add extra columns' do
|
333
|
-
result = '
|
334
|
-
result << ' SELECT COUNT(*)'
|
327
|
+
result = 'SELECT COUNT(*)'
|
335
328
|
result << ' FROM "activities"'
|
336
|
-
result << ' INNER JOIN "record_class" ON "record_class"."oid" = "activities"."tableoid"'
|
337
329
|
result << ' LEFT OUTER JOIN "activity_books" "i_0" ON "activities"."id" = "i_0"."id"'
|
338
330
|
result << ' LEFT OUTER JOIN "activity_posts" "i_1" ON "activities"."id" = "i_1"."id"'
|
339
331
|
result << ' LEFT OUTER JOIN "activity_post_samples" "i_2" ON "activities"."id" = "i_2"."id"'
|
@@ -342,10 +334,8 @@ RSpec.describe 'TableInheritance' do
|
|
342
334
|
end
|
343
335
|
|
344
336
|
it 'works with sum and does not add extra columns' do
|
345
|
-
result = '
|
346
|
-
result << ' SELECT SUM("activities"."id")'
|
337
|
+
result = 'SELECT SUM("activities"."id")'
|
347
338
|
result << ' FROM "activities"'
|
348
|
-
result << ' INNER JOIN "record_class" ON "record_class"."oid" = "activities"."tableoid"'
|
349
339
|
result << ' LEFT OUTER JOIN "activity_books" "i_0" ON "activities"."id" = "i_0"."id"'
|
350
340
|
result << ' LEFT OUTER JOIN "activity_posts" "i_1" ON "activities"."id" = "i_1"."id"'
|
351
341
|
result << ' LEFT OUTER JOIN "activity_post_samples" "i_2" ON "activities"."id" = "i_2"."id"'
|
@@ -387,10 +377,10 @@ RSpec.describe 'TableInheritance' do
|
|
387
377
|
base.create(title: 'Activity test')
|
388
378
|
child.create(title: 'Activity book')
|
389
379
|
other.create(name: 'An author name')
|
380
|
+
base.instance_variable_set(:@casted_dependents, nil)
|
390
381
|
end
|
391
382
|
|
392
383
|
it 'does not affect normal records' do
|
393
|
-
base.instance_variable_set(:@casted_dependents, {})
|
394
384
|
expect(base.first.cast_record).to be_a(base)
|
395
385
|
expect(child.first.cast_record).to be_a(child)
|
396
386
|
expect(other.first.cast_record).to be_a(other)
|
@@ -408,9 +398,28 @@ RSpec.describe 'TableInheritance' do
|
|
408
398
|
end
|
409
399
|
|
410
400
|
it 'does trigger record casting when accessed through inheritance' do
|
411
|
-
base.instance_variable_set(:@casted_dependents, nil)
|
412
401
|
expect(base.second.cast_record).to eql(child.first)
|
413
402
|
end
|
403
|
+
|
404
|
+
context 'using uuid' do
|
405
|
+
let(:base) { Question }
|
406
|
+
let(:child) { QuestionSelect }
|
407
|
+
|
408
|
+
before :each do
|
409
|
+
base.create(title: 'Simple question')
|
410
|
+
child.create(title: 'Select question')
|
411
|
+
base.instance_variable_set(:@casted_dependents, nil)
|
412
|
+
end
|
413
|
+
|
414
|
+
it 'does not affect normal records' do
|
415
|
+
expect(base.first.cast_record).to be_a(base)
|
416
|
+
expect(child.first.cast_record).to be_a(child)
|
417
|
+
end
|
418
|
+
|
419
|
+
it 'does trigger record casting when accessed through inheritance' do
|
420
|
+
expect(base.second.cast_record).to eql(child.first)
|
421
|
+
end
|
422
|
+
end
|
414
423
|
end
|
415
424
|
end
|
416
425
|
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: 2.
|
4
|
+
version: 2.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carlos Silva
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -262,6 +262,8 @@ files:
|
|
262
262
|
- spec/models/guest_comment.rb
|
263
263
|
- spec/models/item.rb
|
264
264
|
- spec/models/post.rb
|
265
|
+
- spec/models/question.rb
|
266
|
+
- spec/models/question_select.rb
|
265
267
|
- spec/models/tag.rb
|
266
268
|
- spec/models/text.rb
|
267
269
|
- spec/models/time_keeper.rb
|
@@ -327,6 +329,8 @@ test_files:
|
|
327
329
|
- spec/models/time_keeper.rb
|
328
330
|
- spec/models/video.rb
|
329
331
|
- spec/models/item.rb
|
332
|
+
- spec/models/question.rb
|
333
|
+
- spec/models/question_select.rb
|
330
334
|
- spec/factories/authors.rb
|
331
335
|
- spec/factories/comments.rb
|
332
336
|
- spec/factories/posts.rb
|
@@ -336,11 +340,9 @@ test_files:
|
|
336
340
|
- spec/factories/videos.rb
|
337
341
|
- spec/factories/item.rb
|
338
342
|
- spec/tests/geometric_builder_spec.rb
|
339
|
-
- spec/tests/arel_spec.rb
|
340
|
-
- spec/tests/insert_all_spec.rb
|
341
343
|
- spec/tests/enum_spec.rb
|
342
|
-
- spec/tests/period_spec.rb
|
343
344
|
- spec/tests/range_spec.rb
|
345
|
+
- spec/tests/table_inheritance_spec.rb
|
344
346
|
- spec/tests/collector_spec.rb
|
345
347
|
- spec/tests/distinct_on_spec.rb
|
346
348
|
- spec/tests/interval_spec.rb
|
@@ -348,10 +350,12 @@ test_files:
|
|
348
350
|
- spec/tests/quoting_spec.rb
|
349
351
|
- spec/tests/relation_spec.rb
|
350
352
|
- spec/tests/auxiliary_statement_spec.rb
|
353
|
+
- spec/tests/belongs_to_many_spec.rb
|
351
354
|
- spec/tests/enum_set_spec.rb
|
352
355
|
- spec/tests/has_many_spec.rb
|
353
|
-
- spec/tests/
|
354
|
-
- spec/tests/
|
356
|
+
- spec/tests/insert_all_spec.rb
|
357
|
+
- spec/tests/arel_spec.rb
|
358
|
+
- spec/tests/period_spec.rb
|
355
359
|
- spec/mocks/cache_query.rb
|
356
360
|
- spec/mocks/create_table.rb
|
357
361
|
- spec/en.yml
|