torque-postgresql 2.1.0 → 2.2.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 (33) hide show
  1. checksums.yaml +4 -4
  2. data/lib/torque/postgresql/adapter/database_statements.rb +3 -15
  3. data/lib/torque/postgresql/adapter/quoting.rb +1 -1
  4. data/lib/torque/postgresql/adapter/schema_dumper.rb +2 -2
  5. data/lib/torque/postgresql/adapter/schema_statements.rb +5 -1
  6. data/lib/torque/postgresql/adapter.rb +20 -4
  7. data/lib/torque/postgresql/associations/belongs_to_many_association.rb +8 -6
  8. data/lib/torque/postgresql/associations/preloader/association.rb +2 -2
  9. data/lib/torque/postgresql/attributes/builder/enum.rb +5 -5
  10. data/lib/torque/postgresql/attributes/builder/period.rb +2 -6
  11. data/lib/torque/postgresql/attributes/enum.rb +1 -1
  12. data/lib/torque/postgresql/attributes/enum_set.rb +1 -1
  13. data/lib/torque/postgresql/base.rb +1 -1
  14. data/lib/torque/postgresql/config.rb +6 -0
  15. data/lib/torque/postgresql/inheritance.rb +1 -1
  16. data/lib/torque/postgresql/reflection/belongs_to_many_reflection.rb +4 -2
  17. data/lib/torque/postgresql/relation/inheritance.rb +9 -14
  18. data/lib/torque/postgresql/version.rb +1 -1
  19. data/lib/torque/postgresql.rb +0 -1
  20. data/lib/torque/range.rb +0 -2
  21. data/spec/factories/item.rb +5 -0
  22. data/spec/models/item.rb +3 -0
  23. data/spec/models/question.rb +3 -0
  24. data/spec/models/question_select.rb +2 -0
  25. data/spec/schema.rb +19 -1
  26. data/spec/tests/arel_spec.rb +30 -0
  27. data/spec/tests/belongs_to_many_spec.rb +31 -10
  28. data/spec/tests/period_spec.rb +9 -0
  29. data/spec/tests/range_spec.rb +1 -1
  30. data/spec/tests/table_inheritance_spec.rb +30 -21
  31. metadata +37 -32
  32. data/lib/torque/postgresql/coder.rb +0 -133
  33. data/spec/tests/coder_spec.rb +0 -367
@@ -1,367 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe 'Complex coder', type: :helper do
4
- let(:coder) { Torque::PostgreSQL::Coder }
5
-
6
- context 'on decode' do
7
-
8
- context 'one dimensional arrays' do
9
- it 'returns an empty array' do
10
- expect(coder.decode(%[{}])).to eql []
11
- end
12
-
13
- it 'returns an array of strings' do
14
- expect(coder.decode(%[{1,2,3}])).to eql ['1','2','3']
15
- end
16
-
17
- it 'returns an array of strings, with nils replacing NULL characters' do
18
- expect(coder.decode(%[{1,,NULL}])).to eql ['1',nil,nil]
19
- end
20
-
21
- it 'returns an array with the word NULL' do
22
- expect(coder.decode(%[{1,"NULL",3}])).to eql ['1','NULL','3']
23
- end
24
-
25
- it 'returns an array of strings when containing commas in a quoted string' do
26
- expect(coder.decode(%[{1,"2,3",4}])).to eql ['1','2,3','4']
27
- end
28
-
29
- it 'returns an array of strings when containing an escaped quote' do
30
- expect(coder.decode(%[{1,"2\\",3",4}])).to eql ['1','2",3','4']
31
- end
32
-
33
- it 'returns an array of strings when containing an escaped backslash' do
34
- expect(coder.decode(%[{1,"2\\\\",3,4}])).to eql ['1','2\\','3','4']
35
- expect(coder.decode(%[{1,"2\\\\\\",3",4}])).to eql ['1','2\\",3','4']
36
- end
37
-
38
- it 'returns an array containing empty strings' do
39
- expect(coder.decode(%[{1,"",3,""}])).to eql ['1', '', '3', '']
40
- end
41
-
42
- it 'returns an array containing unicode strings' do
43
- expect(coder.decode(%[{"Paragraph 399(b)(i) – “valid leave” – meaning"}])).to eq(['Paragraph 399(b)(i) – “valid leave” – meaning'])
44
- end
45
- end
46
-
47
- context 'two dimensional arrays' do
48
- it 'returns an empty array' do
49
- expect(coder.decode(%[{{}}])).to eql [[]]
50
- expect(coder.decode(%[{{},{}}])).to eql [[],[]]
51
- end
52
-
53
- it 'returns an array of strings with a sub array' do
54
- expect(coder.decode(%[{1,{2,3},4}])).to eql ['1',['2','3'],'4']
55
- end
56
-
57
- it 'returns an array of strings with a sub array' do
58
- expect(coder.decode(%[{1,{"2,3"},4}])).to eql ['1',['2,3'],'4']
59
- end
60
-
61
- it 'returns an array of strings with a sub array and a quoted }' do
62
- expect(coder.decode(%[{1,{"2,}3",,NULL},4}])).to eql ['1',['2,}3',nil,nil],'4']
63
- end
64
-
65
- it 'returns an array of strings with a sub array and a quoted {' do
66
- expect(coder.decode(%[{1,{"2,{3"},4}])).to eql ['1',['2,{3'],'4']
67
- end
68
-
69
- it 'returns an array of strings with a sub array and a quoted { and escaped quote' do
70
- expect(coder.decode(%[{1,{"2\\",{3"},4}])).to eql ['1',['2",{3'],'4']
71
- end
72
-
73
- it 'returns an array of strings with a sub array with empty strings' do
74
- expect(coder.decode(%[{1,{""},4,{""}}])).to eql ['1',[''],'4',['']]
75
- end
76
- end
77
-
78
- context 'three dimensional arrays' do
79
- it 'returns an empty array' do
80
- expect(coder.decode(%[{{{}}}])).to eql [[[]]]
81
- expect(coder.decode(%[{{{},{}},{{},{}}}])).to eql [[[],[]],[[],[]]]
82
- end
83
-
84
- it 'returns an array of strings with sub arrays' do
85
- expect(coder.decode(%[{1,{2,{3,4}},{NULL,,6},7}])).to eql ['1',['2',['3','4']],[nil,nil,'6'],'7']
86
- end
87
- end
88
-
89
- context 'record syntax' do
90
- it 'returns an empty array' do
91
- expect(coder.decode(%[()])).to eql []
92
- end
93
-
94
- it 'returns an array of strings' do
95
- expect(coder.decode(%[(1,2,3)])).to eql ['1','2','3']
96
- end
97
-
98
- it 'returns an array of strings, with nils replacing NULL characters' do
99
- expect(coder.decode(%[(1,,NULL)])).to eql ['1',nil,nil]
100
- end
101
-
102
- it 'returns an array with the word NULL' do
103
- expect(coder.decode(%[(1,"NULL",3)])).to eql ['1','NULL','3']
104
- end
105
-
106
- it 'returns an array of strings when containing commas in a quoted string' do
107
- expect(coder.decode(%[(1,"2,3",4)])).to eql ['1','2,3','4']
108
- end
109
-
110
- it 'returns an array of strings when containing an escaped quote' do
111
- expect(coder.decode(%[(1,"2\\",3",4)])).to eql ['1','2",3','4']
112
- end
113
-
114
- it 'returns an array of strings when containing an escaped backslash' do
115
- expect(coder.decode(%[(1,"2\\\\",3,4)])).to eql ['1','2\\','3','4']
116
- expect(coder.decode(%[(1,"2\\\\\\",3",4)])).to eql ['1','2\\",3','4']
117
- end
118
-
119
- it 'returns an array containing empty strings' do
120
- expect(coder.decode(%[(1,"",3,"")])).to eql ['1', '', '3', '']
121
- end
122
-
123
- it 'returns an array containing unicode strings' do
124
- expect(coder.decode(%[("Paragraph 399(b)(i) – “valid leave” – meaning")])).to eq(['Paragraph 399(b)(i) – “valid leave” – meaning'])
125
- end
126
- end
127
-
128
- context 'array of records' do
129
- it 'returns an empty array' do
130
- expect(coder.decode(%[{()}])).to eql [[]]
131
- expect(coder.decode(%[{(),()}])).to eql [[],[]]
132
- end
133
-
134
- it 'returns an array of strings with a sub array' do
135
- expect(coder.decode(%[{1,(2,3),4}])).to eql ['1',['2','3'],'4']
136
- end
137
-
138
- it 'returns an array of strings with a sub array' do
139
- expect(coder.decode(%[{1,("2,3"),4}])).to eql ['1',['2,3'],'4']
140
- end
141
-
142
- it 'returns an array of strings with a sub array and a quoted }' do
143
- expect(coder.decode(%[{1,("2,}3",,NULL),4}])).to eql ['1',['2,}3',nil,nil],'4']
144
- end
145
-
146
- it 'returns an array of strings with a sub array and a quoted {' do
147
- expect(coder.decode(%[{1,("2,{3"),4}])).to eql ['1',['2,{3'],'4']
148
- end
149
-
150
- it 'returns an array of strings with a sub array and a quoted { and escaped quote' do
151
- expect(coder.decode(%[{1,("2\\",{3"),4}])).to eql ['1',['2",{3'],'4']
152
- end
153
-
154
- it 'returns an array of strings with a sub array with empty strings' do
155
- expect(coder.decode(%[{1,(""),4,("")}])).to eql ['1',[''],'4',['']]
156
- end
157
- end
158
-
159
- context 'mix of record and array' do
160
- it 'returns an empty array' do
161
- expect(coder.decode(%[({()})])).to eql [[[]]]
162
- expect(coder.decode(%[{({},{}),{(),{}}}])).to eql [[[],[]],[[],[]]]
163
- end
164
-
165
- it 'returns an array of strings with sub arrays' do
166
- expect(coder.decode(%[{1,(2,{3,4}),(NULL,,6),7}])).to eql ['1',['2',['3','4']],[nil,nil,'6'],'7']
167
- end
168
- end
169
-
170
- context 'record complex sample' do
171
- it 'may have double double quotes translate to single double quotes' do
172
- expect(coder.decode(%[("Test with double "" quoutes")])).to eql ['Test with double " quoutes']
173
- end
174
-
175
- it 'double double quotes may occur any number of times' do
176
- expect(coder.decode(%[("Only one ""","Now "" two "".",""",""{""}","""""")])).to eql ['Only one "', 'Now " two ".', '","{"}', '""']
177
- end
178
-
179
- it 'may have any kind of value' do
180
- expect(coder.decode(%[(String,123456,false,true,"2016-01-01 12:00:00",{1,2,3})])).to eql ['String', '123456', 'false', 'true', '2016-01-01 12:00:00', ['1', '2', '3']]
181
- end
182
- end
183
-
184
- end
185
-
186
- context 'on encode' do
187
- let(:record) { Torque::PostgreSQL::Coder::Record }
188
-
189
- context 'one dimensional arrays' do
190
- it 'receives an empty array' do
191
- expect(coder.encode([])).to eql %[{}]
192
- end
193
-
194
- it 'receives an array of strings' do
195
- expect(coder.encode(['1','2','3'])).to eql %[{1,2,3}]
196
- end
197
-
198
- it 'receives an array of strings, with nils replacing NULL characters' do
199
- expect(coder.encode(['1',nil,nil])).to eql %[{1,NULL,NULL}]
200
- end
201
-
202
- it 'receives an array with the word NULL' do
203
- expect(coder.encode(['1','NULL','3'])).to eql %[{1,"NULL",3}]
204
- end
205
-
206
- it 'receives an array of strings when containing commas in a quoted string' do
207
- expect(coder.encode(['1','2,3','4'])).to eql %[{1,"2,3",4}]
208
- end
209
-
210
- it 'receives an array of strings when containing an escaped quote' do
211
- expect(coder.encode(['1','2",3','4'])).to eql %[{1,"2\\",3",4}]
212
- end
213
-
214
- it 'receives an array of strings when containing an escaped backslash' do
215
- expect(coder.encode(['1','2\\','3','4'])).to eql %[{1,"2\\\\",3,4}]
216
- expect(coder.encode(['1','2\\",3','4'])).to eql %[{1,"2\\\\\\",3",4}]
217
- end
218
-
219
- it 'receives an array containing empty strings' do
220
- expect(coder.encode(['1', '', '3', ''])).to eql %[{1,"",3,""}]
221
- end
222
-
223
- it 'receives an array containing unicode strings' do
224
- expect(coder.encode(['Paragraph 399(b)(i) – “valid leave” – meaning'])).to eql %[{"Paragraph 399(b)(i) – “valid leave” – meaning"}]
225
- end
226
- end
227
-
228
- context 'two dimensional arrays' do
229
- it 'receives an empty array' do
230
- expect(coder.encode([[]])).to eql %[{{}}]
231
- expect(coder.encode([[],[]])).to eql %[{{},{}}]
232
- end
233
-
234
- it 'receives an array of strings with a sub array' do
235
- expect(coder.encode(['1',['2','3'],'4'])).to eql %[{1,{2,3},4}]
236
- end
237
-
238
- it 'receives an array of strings with a sub array' do
239
- expect(coder.encode(['1',['2,3'],'4'])).to eql %[{1,{"2,3"},4}]
240
- end
241
-
242
- it 'receives an array of strings with a sub array and a quoted }' do
243
- expect(coder.encode(['1',['2,}3',nil,nil],'4'])).to eql %[{1,{"2,}3",NULL,NULL},4}]
244
- end
245
-
246
- it 'receives an array of strings with a sub array and a quoted {' do
247
- expect(coder.encode(['1',['2,{3'],'4'])).to eql %[{1,{"2,{3"},4}]
248
- end
249
-
250
- it 'receives an array of strings with a sub array and a quoted { and escaped quote' do
251
- expect(coder.encode(['1',['2",{3'],'4'])).to eql %[{1,{"2\\",{3"},4}]
252
- end
253
-
254
- it 'receives an array of strings with a sub array with empty strings' do
255
- expect(coder.encode(['1',[''],'4',['']])).to eql %[{1,{""},4,{""}}]
256
- end
257
- end
258
-
259
- context 'three dimensional arrays' do
260
- it 'receives an empty array' do
261
- expect(coder.encode([[[]]])).to eql %[{{{}}}]
262
- expect(coder.encode([[[],[]],[[],[]]])).to eql %[{{{},{}},{{},{}}}]
263
- end
264
-
265
- it 'receives an array of strings with sub arrays' do
266
- expect(coder.encode(['1',['2',['3','4']],[nil,nil,'6'],'7'])).to eql %[{1,{2,{3,4}},{NULL,NULL,6},7}]
267
- end
268
- end
269
-
270
- context 'record syntax' do
271
- it 'receives an empty array' do
272
- expect(coder.encode( record.new )).to eql %[()]
273
- end
274
-
275
- it 'receives an array of strings' do
276
- expect(coder.encode( record.new(['1','2','3']) )).to eql %[(1,2,3)]
277
- end
278
-
279
- it 'receives an array of strings, with nils replacing NULL characters' do
280
- expect(coder.encode( record.new(['1',nil,nil]) )).to eql %[(1,,)]
281
- end
282
-
283
- it 'receives an array with the word NULL' do
284
- expect(coder.encode( record.new(['1','NULL','3']) )).to eql %[(1,"NULL",3)]
285
- end
286
-
287
- it 'receives an array of strings when containing commas in a quoted string' do
288
- expect(coder.encode( record.new(['1','2,3','4']) )).to eql %[(1,"2,3",4)]
289
- end
290
-
291
- it 'receives an array of strings when containing an escaped quote' do
292
- expect(coder.encode( record.new(['1','2",3','4']) )).to eql %[(1,"2\\",3",4)]
293
- end
294
-
295
- it 'receives an array of strings when containing an escaped backslash' do
296
- expect(coder.encode( record.new(['1','2\\','3','4']) )).to eql %[(1,"2\\\\",3,4)]
297
- expect(coder.encode( record.new(['1','2\\",3','4']) )).to eql %[(1,"2\\\\\\",3",4)]
298
- end
299
-
300
- it 'receives an array containing empty strings' do
301
- expect(coder.encode( record.new(['1', '', '3', '']) )).to eql %[(1,"",3,"")]
302
- end
303
-
304
- it 'receives an array containing unicode strings' do
305
- expect(coder.encode( record.new(['Paragraph 399(b)(i) – “valid leave” – meaning']) )).to eql %[("Paragraph 399(b)(i) – “valid leave” – meaning")]
306
- end
307
- end
308
-
309
- context 'array of records' do
310
- it 'receives an empty array' do
311
- expect(coder.encode([record.new])).to eql %[{()}]
312
- expect(coder.encode([record.new,record.new])).to eql %[{(),()}]
313
- end
314
-
315
- it 'receives an array of strings with a sub array' do
316
- expect(coder.encode(['1',record.new(['2','3']),'4'])).to eql %[{1,(2,3),4}]
317
- end
318
-
319
- it 'receives an array of strings with a sub array' do
320
- expect(coder.encode(['1',record.new(['2,3']),'4'])).to eql %[{1,("2,3"),4}]
321
- end
322
-
323
- it 'receives an array of strings with a sub array and a quoted }' do
324
- expect(coder.encode(['1',record.new(['2,}3',nil,nil]),'4'])).to eql %[{1,("2,}3",,),4}]
325
- end
326
-
327
- it 'receives an array of strings with a sub array and a quoted {' do
328
- expect(coder.encode(['1',record.new(['2,{3']),'4'])).to eql %[{1,("2,{3"),4}]
329
- end
330
-
331
- it 'receives an array of strings with a sub array and a quoted { and escaped quote' do
332
- expect(coder.encode(['1',record.new(['2",{3']),'4'])).to eql %[{1,("2\\",{3"),4}]
333
- end
334
-
335
- it 'receives an array of strings with a sub array with empty strings' do
336
- expect(coder.encode(['1',record.new(['']),'4',record.new([''])])).to eql %[{1,(""),4,("")}]
337
- end
338
- end
339
-
340
- context 'mix of record and array' do
341
- it 'receives an empty array' do
342
- expect(coder.encode( record.new([[record.new,nil]]) )).to eql %[({(),NULL})]
343
- expect(coder.encode( [record.new([[], []]),[record.new,[]]] )).to eql %[{({},{}),{(),{}}}]
344
- end
345
-
346
- it 'receives an array of strings with sub arrays' do
347
- expect(coder.encode(['1',record.new(['2',['3','4']]),record.new([nil,nil,'6']),'7'])).to eql %[{1,(2,{3,4}),(,,6),7}]
348
- end
349
- end
350
-
351
- context 'record complex sample' do
352
- it 'may have double double quotes translate to single double quotes' do
353
- expect(coder.encode( record.new(['Test with double " quoutes']) )).to eql %[("Test with double \\" quoutes")]
354
- end
355
-
356
- it 'double double quotes may occur any number of times' do
357
- expect(coder.encode( record.new(['Only one "', 'Now " two ".', '","{"}', '""']) )).to eql %[("Only one \\"","Now \\" two \\".","\\",\\"{\\"}","\\"\\"")]
358
- end
359
-
360
- it 'may have any kind of value' do
361
- expect(coder.encode( record.new(['String', '123456', 'false', 'true', '2016-01-01 12:00:00', ['1', '2', '3']]) )).to eql %[(String,123456,false,true,"2016-01-01 12:00:00",{1,2,3})]
362
- end
363
- end
364
-
365
- end
366
-
367
- end